Go Back   vb.org Archive > vBulletin 4 Discussion > vB4 Programming Discussions
FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools Display Modes
  #1  
Old 07-24-2013, 07:49 PM
DRJ DRJ is offline
 
Join Date: Jan 2005
Location: California USA
Posts: 164
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default Using variables in templates

I am having issues with this. I just upgraded from 3 to 4 and want to have a variable that I can use in an If Statement in a template.

So in a template I can do this:

<vb:if condition="$var == 1">

In a pluggin I can do this:

Code:
$var=1;
vB_Template::preRegister('header',array('var' => $var));
Now if I use
Code:
{vb:raw var}
I get the value but when I try to use that in an If statement I can't get it to work.

If I try to use $var I just get the text $var and not the value.

Please advise.

Thanks
Reply With Quote
  #2  
Old 07-24-2013, 07:55 PM
Zachery's Avatar
Zachery Zachery is offline
 
Join Date: Jul 2002
Location: Ontario, Canada
Posts: 11,440
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

You're likely putting your code in the wrong plugin, which pluigin do you have it in, did you try moving it to another plugin point?
Reply With Quote
  #3  
Old 07-24-2013, 08:20 PM
tbworld tbworld is offline
 
Join Date: Oct 2008
Posts: 2,126
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

What template are you trying to insert into?
Reply With Quote
  #4  
Old 07-24-2013, 09:32 PM
DRJ DRJ is offline
 
Join Date: Jan 2005
Location: California USA
Posts: 164
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I added it to global start, I tried a few others but was just guessing at that point.

I want it in the header.

If I do VB:Raw I can get the value no problem.

But if I do $Var, I get just the text.

The issue being I want to be able to use an If Statement.

Basically this is for ads and I have a variable saying what type it is, 1 for flash, 2 for image. Before I had an If conditional and based on that variable I could play the flash or add a hyperlink for the image.

But can't seem to get the syntax right for using the variable in the If statement.

Thanks
Reply With Quote
  #5  
Old 07-24-2013, 11:25 PM
tbworld tbworld is offline
 
Join Date: Oct 2008
Posts: 2,126
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by DRJ View Post
I am having issues with this. I just upgraded from 3 to 4 and want to have a variable that I can use in an If Statement in a template.

So in a template I can do this:

<vb:if condition="$var == 1">

In a pluggin I can do this:

Code:
$var=1;
vB_Template::preRegister('header',array('var' => $var));
Now if I use
Code:
{vb:raw var}
I get the value but when I try to use that in an If statement I can't get it to work.
Thanks
Try hook: parse_templates

Show me your "if condition" statement.
Reply With Quote
  #6  
Old 07-25-2013, 04:00 AM
DRJ DRJ is offline
 
Join Date: Jan 2005
Location: California USA
Posts: 164
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Not sure what I was doing wrong before, but now it seems to be working fine.

I ended up deactivating all the custom plugins because I was getting errors elsewhere. And now when I try adding these variables the same way I was before it works so not sure what was the cause of the issue.

Could have been a typo as well but I tried it several times with simple variables like $x and it wouldn't work so not really sure.

Thanks for the assistance.
Reply With Quote
  #7  
Old 07-25-2013, 04:06 AM
tbworld tbworld is offline
 
Join Date: Oct 2008
Posts: 2,126
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by DRJ View Post
Not sure what I was doing wrong before, but now it seems to be working fine.

I ended up deactivating all the custom plugins because I was getting errors elsewhere. And now when I try adding these variables the same way I was before it works so not sure what was the cause of the issue.

Could have been a typo as well but I tried it several times with simple variables like $x and it wouldn't work so not really sure.

Thanks for the assistance.
Reading here on vb.org, it is not uncommon to hear that solution. I think the plugin cache in the datastore for some reason does not get updated.

I currently have a board that is doing the same behavior, but only on "headinclude". The template is rendered correctly in database, the right plugin code is in the datastore, the right template page (styleid) is displaying -- yet the variable is not being replaced in the template. I am a bit baffled, but I aim to track down the problem tonight.

I normally just put the code directly in the template, but after reading your post and @chris's; I decided to check it out.
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 08:00 AM.


Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2024, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.07946 seconds
  • Memory Usage 2,226KB
  • Queries Executed 13 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)ad_showthread_beforeqr
  • (1)ad_showthread_firstpost
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (4)bbcode_code
  • (2)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (7)post_thanks_box
  • (7)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (7)post_thanks_postbit_info
  • (7)postbit
  • (7)postbit_onlinestatus
  • (7)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available:
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files:
  • ./showthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_post_thanks.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_postinfo_query
  • fetch_postinfo
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • forumjump
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • fetch_musername
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete