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 04-14-2011, 07:18 PM
toodimm toodimm is offline
 
Join Date: Mar 2011
Posts: 5
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default 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
Reply With Quote
  #2  
Old 04-14-2011, 09:06 PM
Lynne's Avatar
Lynne Lynne is offline
 
Join Date: Sep 2004
Location: California/Idaho
Posts: 41,180
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Cellarius wrote a really good article that you may be interested in - [vB4] Rendering templates and registering variables - a short guide
Reply With Quote
  #3  
Old 04-14-2011, 09:28 PM
toodimm toodimm is offline
 
Join Date: Mar 2011
Posts: 5
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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.
Reply With Quote
  #4  
Old 04-14-2011, 10:44 PM
Lynne's Avatar
Lynne Lynne is offline
 
Join Date: Sep 2004
Location: California/Idaho
Posts: 41,180
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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.
Reply With Quote
  #5  
Old 04-14-2011, 11:53 PM
toodimm toodimm is offline
 
Join Date: Mar 2011
Posts: 5
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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!
Reply With Quote
  #6  
Old 08-27-2013, 04:50 PM
BlueChipEarth's Avatar
BlueChipEarth BlueChipEarth is offline
 
Join Date: Apr 2009
Posts: 21
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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.
Reply With Quote
  #7  
Old 08-27-2013, 04:59 PM
Zachery's Avatar
Zachery Zachery is offline
 
Join Date: Jul 2002
Location: Ontario, Canada
Posts: 11,440
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Did you try template_register_var ?
Reply With Quote
  #8  
Old 08-27-2013, 05:03 PM
nhawk nhawk is offline
 
Join Date: Jan 2011
Posts: 1,604
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Your code, exactly as you have it posted works for me.
Attached Images
File Type: jpg p1.jpg (234.2 KB, 0 views)
File Type: jpg p2.jpg (369.6 KB, 0 views)
File Type: jpg p3.jpg (59.4 KB, 0 views)
Reply With Quote
Благодарность от:
BlueChipEarth
  #9  
Old 08-27-2013, 05:37 PM
BlueChipEarth's Avatar
BlueChipEarth BlueChipEarth is offline
 
Join Date: Apr 2009
Posts: 21
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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!?
Reply With Quote
  #10  
Old 08-27-2013, 05:54 PM
nhawk nhawk is offline
 
Join Date: Jan 2011
Posts: 1,604
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

The conditional the way you have it is correct.
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 01:35 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.05881 seconds
  • Memory Usage 2,277KB
  • Queries Executed 14 (?)
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
  • (3)bbcode_code
  • (1)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (1)pagenav_pagelink
  • (10)post_thanks_box
  • (1)post_thanks_box_bit
  • (10)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (1)post_thanks_postbit
  • (10)post_thanks_postbit_info
  • (10)postbit
  • (3)postbit_attachment
  • (10)postbit_onlinestatus
  • (10)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
  • fetch_musername
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • post_thanks_function_fetch_thanks_bit_start
  • post_thanks_function_show_thanks_date_start
  • post_thanks_function_show_thanks_date_end
  • post_thanks_function_fetch_thanks_bit_end
  • post_thanks_function_fetch_post_thanks_template_start
  • post_thanks_function_fetch_post_thanks_template_end
  • postbit_attachment
  • pagenav_page
  • pagenav_complete
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete