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 |
#302
|
|||
|
|||
I think using member_build_blocks_start is much better than member_complete as it allows you to access function preRegister of vB_Template class.
|
#303
|
|||
|
|||
JUst a quick question
Playing with 4.2.2 Tried using the $templater but no dice but (Sorted) BUT !!!! eval does work ? is this right ? PHP Code:
|
#304
|
|||
|
|||
Quote:
Code:
$templater = vB_Template::create('testtest'); $templater->register('var1', $var1); $template_hook[global_below_navbar] .= $templater->render(); |
#305
|
|||
|
|||
Help me please! What I`m do wrong?...
I trying show some info on showthread page. ----------------------------------------------------------------- PHP Code:
HTML Code:
<template name="rightside_on_showthread" templatetype="template" date="1337106668" username="taravasya" version="1.0.0"><![CDATA[ <div class="rightsideinfo">{vb:raw mynewvar}</div> ]]></template> And so on SHOWTHREAD template I adding: HTML Code:
{vb:raw rightside_on_showthread} But with no luck ((( In place in what I was want to add my info I have white space(without my div class="rightsideinfo" in inspector of page). But in debug info, I have not cached template rightside_on_showthread. UPDATE ------------------------------------- I was thinking if I take vars into my own template, then I don`t need to use vB_Template:: preRegister for add my template in showthread. But I was wrong...)) |
#306
|
||||
|
||||
PHP Code:
|
2 благодарности(ей) от: | ||
taravasya, TheLastSuperman |
#307
|
|||
|
|||
Thanks, Lynne! Actually I wrote in a previous message, that I understood my mistake, but your variant helped me to make my code more succinctly! Thanks!
|
#308
|
|||
|
|||
Another problem(((
In hook showthread_similarthreadbit I add next code: PHP Code:
This hook added in showthread.php on 1978. I was thinking, if this hook placed in a while cycle, I will have all results from this cycle. But no.... |
#309
|
|||
|
|||
Hi
my plugin load in "showthread_complete" and it's code is: PHP Code:
Code:
<meta property="og:title" content="{vb:raw pagetitle} - page {vb:raw pagenumber} of {vb:raw totalpages} pages" /> I need to point out that I can not load the plugin in the "parse_template". Because the page number and other variable is not recognized in "parse_template". and why "{vb:rawphrase thread.title}" not work in my template? |
|
|
X vBulletin 3.8.12 by vBS Debug Information | |
---|---|
|
|
More Information | |
Template Usage:
Phrase Groups Available:
|
Included Files:
Hooks Called:
|