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 12-30-2009, 09:37 PM
Tamtams Tamtams is offline
 
Join Date: Nov 2009
Posts: 24
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default How to call a variable from within the Threadbit template?

I'm trying to convert over a vb3 product to vb4, and am running into an issue with the template system. Specifically, I am having trouble passing a variable to be outputted from within the template.

I am using the following code in a plugin which has the hook location of threadbit_display:

PHP Code:
$templater vB_Template::create('custom_template');
$templater->register('my_var'$my_var);
$templatevalues['custom_template'] = $templater->render();
vB_Template::preRegister('threadbit'$templatevalues); 
Then in the style manager for threadbit, I added the following :
{vb:raw custom_template}

Unfortunately, it didn't work. Also tried {vb:raw custom_template.my_var} and it didn't work.

I've turned on dev mode, and custom_template appears under the list of template usage. It is highlighted in red though - I don't know what that means.

Anyone have any ideas?
Reply With Quote
  #2  
Old 12-30-2009, 10:21 PM
Lynne's Avatar
Lynne Lynne is offline
 
Join Date: Sep 2004
Location: California/Idaho
Posts: 41,180
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

PHP Code:
$templater vB_Template::create('custom_template'); 
$templater->register('my_var'$my_var); 
$custom_template $templater->render(); 
vB_Template::preRegister('threadbit', array('custom_template' => $custom_template)); 
Now you can use {vb:raw custom_template}
Reply With Quote
  #3  
Old 12-31-2009, 03:17 AM
Tamtams Tamtams is offline
 
Join Date: Nov 2009
Posts: 24
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Thanks Lynne - I copied and pasted that code exactly though, and it still didn't work... I changed $my_var to "Test123" just to make sure it was a variable assignment error or anything, but still a no go.

It is ok to be including this code in a plugin which uses hook location threadbit_display, correct?
Reply With Quote
  #4  
Old 12-31-2009, 02:46 PM
Lynne's Avatar
Lynne Lynne is offline
 
Join Date: Sep 2004
Location: California/Idaho
Posts: 41,180
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Do you know if it is your template that isn't rendering or the preregistering that isn't working? Do some debugging in that area to find out (just assign xxx to a variable and preregister is and see if it shows up).
Reply With Quote
  #5  
Old 12-31-2009, 05:06 PM
Tamtams Tamtams is offline
 
Join Date: Nov 2009
Posts: 24
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Hi Lynne - That is exactly what I did - I assigned the value "Test123" to the variable, so it looks like it is the pre-registering which isn't working...

For example -
Code:
$templater = vB_Template::create('custom_template'); 
$templater->register('my_var', 'Test123'); 
$custom_template = $templater->render(); 
vB_Template::preRegister('threadbit', array('custom_template' => $custom_template));
{vb:raw custom_template} does not display "Test123"
Reply With Quote
  #6  
Old 12-31-2009, 05:53 PM
Lynne's Avatar
Lynne Lynne is offline
 
Join Date: Sep 2004
Location: California/Idaho
Posts: 41,180
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

This works just fine for me, so preregistering is working:
PHP Code:
$custom_template 'hello'
vB_Template::preRegister('threadbit', array('custom_template' => $custom_template)); 
Reply With Quote
  #7  
Old 12-31-2009, 07:14 PM
Tamtams Tamtams is offline
 
Join Date: Nov 2009
Posts: 24
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I'm a little mixed up - can I just use these two lines then, and insert whatever variable I want for $custom_template? I.e. is the 4 line version redundant, or do they both versions do the same thing?
Reply With Quote
  #8  
Old 12-31-2009, 07:48 PM
Lynne's Avatar
Lynne Lynne is offline
 
Join Date: Sep 2004
Location: California/Idaho
Posts: 41,180
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

You could just do it with two lines. I thought you had a template you were wanting to use though.
Reply With Quote
  #9  
Old 12-31-2009, 08:19 PM
Tamtams Tamtams is offline
 
Join Date: Nov 2009
Posts: 24
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Well, I think I should be using templates in order to use the cache system, correct? I.e. if I just use pre-register no caching will occur, right?

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

Also - just to clarify - i am able to access the variable using the 2 line version, but when I register as a template I am unable to access the variable.

When I turn on debug mode I can confirm the template is being loaded though. There is a (20) beside it, and its name is highlighted in red (which I assume means its not cached?)
Reply With Quote
  #10  
Old 12-31-2009, 11:09 PM
Lynne's Avatar
Lynne Lynne is offline
 
Join Date: Sep 2004
Location: California/Idaho
Posts: 41,180
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I would guess something is wrong with your template then. Try just putting "hello" in the template and see if you get that to print 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 09:50 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.08862 seconds
  • Memory Usage 2,261KB
  • Queries Executed 11 (?)
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
  • (1)bbcode_code
  • (3)bbcode_php
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (2)pagenav_pagelink
  • (10)post_thanks_box
  • (10)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (10)post_thanks_postbit_info
  • (10)postbit
  • (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_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
  • pagenav_page
  • pagenav_complete
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete