The Arcive of Official vBulletin Modifications Site.It is not a VB3 engine, just a parsed copy! |
|
[HOW TO - vB4] Rendering templates and registering variables - a short guide
Introduction Starting with vB4, templates no longer get output using eval: PHP Code:
What's more: Variables and arrays from plugins that are executed on a page no longer can automatically be accessed in the templates of that page. They need to be registered first. . Basic functionality to render templates and register all variables/arrays you want to use inside PHP Code:
HTML Code:
{vb:raw my_var} {vb:raw my_array.key1} {vb:raw my_array.key2.key21} . . . Now, with the result of the rendering we can do several things: . Output template directly - custom pages PHP Code:
Note the second line, which is special for this type of use: PHP Code:
. Use a template hook PHP Code:
. Save into a variable for later use in custom template PHP Code:
PHP Code:
HTML Code:
{vb:raw my_template_rendered} . Save into an array and preregister to use in an existing/stock template PHP Code:
HTML Code:
{vb:raw my_insertvar} Essentially the same as what I put for preRegister would be the following two lines. They could replace the last two lines in the above php codebox: PHP Code:
. . Bonus track: ...whatever you do, cache your templates! Now you know how to get your templates on screen - once you succeeded in doing that, make sure to do it in a fast and ressource saving manner: make use of vB's template cache. To see whether your templates are cached or not, activate debug mode by adding $config['Misc']['debug'] = true;to your config.php (don't ever use that on your live site!). Among the debug info is a list of all templates called, and non-cached templates will show up in red. To cache your templates, add a plugin at hook cache_templates with the following code: PHP Code:
. Hope this helps! -cel ---- Addendum - There are now two blog posts on vb.com related to this topic: http://www.vbulletin.com/forum/entry...in-4-templates http://www.vbulletin.com/forum/entry...-4-based-files |
#182
|
||||
|
||||
This has been described around the forum several times; either search or open your own thread, this is not related to the topic of this tutorial.
|
#183
|
|||
|
|||
Hello everyone, is there any way to include for example this php:
cotw_func_contest_num.php?do=sotw As a variable in a plugin, then use it in a template? I also created this thread but am also posting here to see if anyone had any further ideas we could try. Any info would be very much appreciated. Thanks for your time everyone. |
#184
|
|||
|
|||
I've been driven nuts. All I want to do is output $random_number using rand(1,99999) and I'm stuck.. why have they made this insanely difficult?
|
#185
|
|||
|
|||
Quote:
Code:
$random_number = rand(1,99999);
vB_Template::preRegister('template_name',array('random_number' => $random_number));
Then in the template put HTML Code:
{vb:raw random_number} |
#186
|
||||
|
||||
Ok been banging my head on this for quite some time now and completely ready to throw in the towel. I dont know why vB had to make things so damn difficult! It used to be really easy and straight forward to extend vB but not so much now.
I just want to pull in my custom template for adding a value to the postbit userifo part using the template hook "postbit_userinfo_right_after_posts" The variable $post[field5] is already pulled in as I can do the eval like so to test it in the plugin... Code:
if ($post['field5']) { $templater = vB_Template::Create('postbit_name'); $template_hook['postbit_userinfo_right_after_posts'] .= $templater->render(); } If I hard code the template instead of creating it it works fine but I want it to be properly developed and not hacked. Thanks |
#187
|
||||
|
||||
Because it's filled in your PHP script, but you never registered it for use in your template, and that's why it's empty there.
The tutorial does state (in bold red ) that you have to register every variable and array you want to use in your custom template. Try: Code:
if ($post['field5']) { $templater = vB_Template::Create('postbit_name'); $templater->register('post', $post) $template_hook['postbit_userinfo_right_after_posts'] .= $templater->render(); } |
#188
|
||||
|
||||
Thank You for the reply but I guess I will have to start over at square 1 to get a better understanding of the new vB4 architechure
Ok now I made that change and it work! So even though the variable/array is a standard vB one because I made a custom template I have to register the standard variables too it seems. I thought it was just our custom variables |
#189
|
|||
|
|||
Quote:
Code:
ob_start(); include('../www/gearstore/jdmgear.php'); $templatevalues['insert_simple_php'] = ob_get_contents(); ob_end_clean(); vB_Template::preRegister('JDMGEAR', $templatevalues); Code:
{vb:raw insert_simple_php} actual page http://nycjdm.com/jdmgear.php any ideas? --------------- Added [DATE]1313595423[/DATE] at [TIME]1313595423[/TIME] --------------- Quote:
I have everything working now i just need to figure out how to intergrate it's login with vb4 if anyone could point me in the right direction that would be great. |
#190
|
||||
|
||||
Ok, I'm probably overlooking something, or didn't do something right, or something lol, but this is my first time trying to include a custom template within another custom template on vB 4 (it was SO much easier on vB 3 )
Anyway, this is where I'm at so far: Plugin Hook location: process_templates_complete PHP Code:
I'm calling my sidebar template in my template usml_military_ranks (and many others) by using: Code:
{vb:raw usml_military_ranks_sidebar} In the PHP file for usml_military_ranks I have: PHP Code:
|
#191
|
|||
|
|||
You might try taking this line out of the php file:
PHP Code:
you don't need this and the PreRegister, and this line might actually be registering an undefined variable. |
Благодарность от: | ||
HMBeaty |
|
|
X vBulletin 3.8.12 by vBS Debug Information | |
---|---|
|
|
More Information | |
Template Usage:
Phrase Groups Available:
|
Included Files:
Hooks Called:
|