vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB4 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=252)
-   -   Plugin variables in template conditionals (https://vborg.vbsupport.ru/showthread.php?t=262019)

toodimm 04-14-2011 07:18 PM

Plugin variables in template conditionals
 
Hi

Any chance that someone could tell me how to declare a variable in a plugin, such that that variable can then be used in a template conditional?

Thanks

Lynne 04-14-2011 09:06 PM

Cellarius wrote a really good article that you may be interested in - [vB4] Rendering templates and registering variables - a short guide

toodimm 04-14-2011 09:28 PM

I really appreciate the link Lynne, but it doesn't actually answer the question I asked, which was:
Quote:

how to declare a variable in a plugin, such that that variable can then be used in a template conditional
As far as I can tell, variables registered with the $templater->register method are only available in templates using {vb:raw my_var}, not in the template conditionals, such as <vb:if condition="$my_plugin_variable == 0">

Any other advise would be gratefully recieved.

Lynne 04-14-2011 10:44 PM

Yeah, you need to preregister the variable for use in the template and then you are allowed to use it in the template conditional. It's the same variable that can be either spit out directly or used in a condition.

toodimm 04-14-2011 11:53 PM

Thank you so much! Did the trick.

Sorry if my previous answer was a little rude, my only excuse is that I'm going nuts because of the complete lack of decent developer documentation available for vbulletin. If I could find the answers out myself, then I wouldn't be bothering the board!

BlueChipEarth 08-27-2013 04:50 PM

I have a variable in the "style_fetch" hook called $mobile (for the mobile device detection mod, unimportant for this question, but that's why it's in "style_fetch").

I cannot, for the life of me, preRegister this variable for the "footer" template!!!


Why does this not work!?

in "style_fetch":

Code:

$TEST = "TESTING";
vB_Template::preRegister('footer', array('TEST' => $TEST));


in "footer" template:
Code:

{vb:raw TEST}
^Doesn't work.

Nor does the variable work in a conditional. What am I doing wrong!? Why does this have to be so complicated and confusing? I haven't seen even one post where someone preRegisters a variable and then uses it in a conditional, either... would the variable above be $TEST?

I'm so frustrated.

Zachery 08-27-2013 04:59 PM

Did you try template_register_var ?

nhawk 08-27-2013 05:03 PM

1 Attachment(s)
Your code, exactly as you have it posted works for me.

BlueChipEarth 08-27-2013 05:37 PM

nhawk, I can't figure out why mine won't work... let me review the code and make sure I'm not in some parent if statement or something...

In the meantime, can you tell me what the registered variable would look like, or how to use it, in a conditional? Would it just be "$TEST" like:

Code:

<vb:if condition="$TEST == 'TESTING'">
        something
</vb:if>

--------------- Added [DATE]1377629193[/DATE] at [TIME]1377629193[/TIME] ---------------

Hmm... seems I had a logic error in my code. I'm working within a mod, as I said earlier, and I think that since I clicked "desktop version" it was completely skipping mobile detection and, therefore, not setting the variable I was trying to access. D'oh!!!

I'm too tired today for programming... lousy downstairs neighbor found 12:30 AM a perfectly acceptable time to practice his guitar. He needs practice, to be sure... but let's do it at normal human hours, eh, Rock'n'Roll Dracula!?

nhawk 08-27-2013 05:54 PM

The conditional the way you have it is correct.


All times are GMT. The time now is 02:28 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.01820 seconds
  • Memory Usage 1,738KB
  • 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
  • (3)bbcode_code_printable
  • (1)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (1)pagenav_pagelink
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (10)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
  • pagenav_page
  • pagenav_complete
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete