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-15-2012, 04:31 PM
extends extends is offline
 
Join Date: Jul 2012
Posts: 13
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default Problem with using plugin variables in templates

So for some time now I have been ripping my hair out trying to figure out how to use my plugin variables in my custom templates. After reading countless threads and articles on preReigsting my variables, I have zero luck in actually accomplishing this task.

Here's my basic ripped plugin example hooking newthread_forum_start

Code:
$my_var = "abc";

$templater = vB_Template::create('newtemplate');

$templater->register('my_var', $my_var);
$myrendervar = $templater->render();

vB_Template::preRegister('newthread',array('myrendervar ' => $myrendervar));
trying to access this variable in newthread using {vb:raw myrendervar} does not work. In fact looking at the debug information "newtemplate" is in bolder red letters. I can easily echo my_var, but I cannot use it in newthead template.

What's the deal? What am I not understanding about plugin variables that's preventing me from using basic ones?
Reply With Quote
  #2  
Old 07-15-2012, 05:01 PM
Lynne's Avatar
Lynne Lynne is offline
 
Join Date: Sep 2004
Location: California/Idaho
Posts: 41,180
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

You didn't register $my_var to be used in newthread, you only registered it to be used in newtemplate.
Reply With Quote
  #3  
Old 07-15-2012, 08:14 PM
soniceffect's Avatar
soniceffect soniceffect is offline
 
Join Date: Feb 2005
Location: UK
Posts: 453
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by extends View Post
So for some time now I have been ripping my hair out trying to figure out how to use my plugin variables in my custom templates. After reading countless threads and articles on preReigsting my variables, I have zero luck in actually accomplishing this task.

Here's my basic ripped plugin example hooking newthread_forum_start

Code:
$my_var = "abc";

$templater = vB_Template::create('newtemplate');

$templater->register('my_var', $my_var);
$myrendervar = $templater->render();

vB_Template::preRegister('newthread',array('myrendervar ' => $myrendervar));
trying to access this variable in newthread using {vb:raw myrendervar} does not work. In fact looking at the debug information "newtemplate" is in bolder red letters. I can easily echo my_var, but I cannot use it in newthead template.

What's the deal? What am I not understanding about plugin variables that's preventing me from using basic ones?

You should have a template created named "newtemplate" with {vb:raw my_var} in it. Are you doing this?
Reply With Quote
  #4  
Old 07-17-2012, 06:24 AM
extends extends is offline
 
Join Date: Jul 2012
Posts: 13
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I got it working thanks to Lynne. I did not know that 'newtemplate' was suppose to target the template I was editing, instead I thought it was some kind of a unique identifier.

But a new problem arises, trying to use my new variable's from the plugin, in a template conditional.

(example)
PHP Code:
$customid 4;
$var2 vB_Template::create('newthread');
$var2->register('checkid'$customid);
$my_var2 $var2->render();
vB_Template::preRegister('newthread',array('checkid' => $my_var2)); 
When I try to use it like so, nothing happens:
(I've used customid as well to cover all my bases)
Code:
<vb:if condition="$foruminfo[forumid] != $checkid"> 
...
</vb:if>
How can I get this to actually work? it never follows through on the conditional.
Reply With Quote
  #5  
Old 07-17-2012, 11:15 AM
soniceffect's Avatar
soniceffect soniceffect is offline
 
Join Date: Feb 2005
Location: UK
Posts: 453
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Have you tried outputting checkid to see what it outputs? This should be your first port of all. Alway output the items you are going to compare to screen to see whether they contain what you expect before you try to compare them.

I believe $foruminfo[forumid] should actually be $forum['forumid']
Reply With Quote
  #6  
Old 07-17-2012, 07:21 PM
extends extends is offline
 
Join Date: Jul 2012
Posts: 13
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by soniceffect View Post
Have you tried outputting checkid to see what it outputs? This should be your first port of all. Alway output the items you are going to compare to screen to see whether they contain what you expect before you try to compare them.

I believe $foruminfo[forumid] should actually be $forum['forumid']
$foruminfo[forumid] is the correct variable to use, when trying to find what forum the user has selected.

I tried printing the variable checkid and instead of getting the number 4, I got "Post new thread" and some submit buttons(as if I re-click new topic). Tab confused on this one, as clearly there's some kind of error within the mapping of the variable. But if I echo $customid I do indeed get 4.

Some where in
PHP Code:
$var2->register('checkid'$customid);
$my_var2 $var2->render(); 
is not setting the number correctly.
Reply With Quote
  #7  
Old 07-17-2012, 07:45 PM
soniceffect's Avatar
soniceffect soniceffect is offline
 
Join Date: Feb 2005
Location: UK
Posts: 453
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

because your actually preregistering the template into itself. You register the variable with newtrhead then you are registering newthread, with newthread
Reply With Quote
  #8  
Old 07-18-2012, 12:17 AM
extends extends is offline
 
Join Date: Jul 2012
Posts: 13
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

oh wow, your absolutely right. I had the idea that you had to go through thous ridiculous loops to per-register your variables.

Got it all working. Thanks.
Reply With Quote
  #9  
Old 07-18-2012, 08:07 AM
soniceffect's Avatar
soniceffect soniceffect is offline
 
Join Date: Feb 2005
Location: UK
Posts: 453
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by extends View Post
oh wow, your absolutely right. I had the idea that you had to go through thous ridiculous loops to per-register your variables.

Got it all working. Thanks.
No prob. Glad its sorted for ya
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:21 PM.


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.04859 seconds
  • Memory Usage 2,254KB
  • 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
  • (3)bbcode_code
  • (2)bbcode_php
  • (3)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (9)post_thanks_box
  • (9)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (9)post_thanks_postbit_info
  • (9)postbit
  • (9)postbit_onlinestatus
  • (9)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