vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB4 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=252)
-   -   Using variables in templates (https://vborg.vbsupport.ru/showthread.php?t=300420)

DRJ 07-24-2013 07:49 PM

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

Zachery 07-24-2013 07:55 PM

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?

tbworld 07-24-2013 08:20 PM

What template are you trying to insert into?

DRJ 07-24-2013 09:32 PM

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

tbworld 07-24-2013 11:25 PM

Quote:

Originally Posted by DRJ (Post 2435165)
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.

DRJ 07-25-2013 04:00 AM

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.

tbworld 07-25-2013 04:06 AM

Quote:

Originally Posted by DRJ (Post 2435253)
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.


All times are GMT. The time now is 12:48 PM.

Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.

X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.01047 seconds
  • Memory Usage 1,727KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (4)bbcode_code_printable
  • (2)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (7)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.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/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • printthread_start
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete