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 |
#212
|
||||
|
||||
Quote:
|
#213
|
||||
|
||||
Go for it. An unnamed dev gave it to me a long while back.
|
#214
|
||||
|
||||
Hey all,
I think i'm being really dumb here, looking for some help. In my Navbar Template i want to call another template that i want to create, rather that adding code irectly into the navbar template. Am i right in thinking that i have to register the code in a php file on the server, or can i do this all via a plug in and templates? if so, does anyone have some code for a simple example, i.e. call 1 new template from within another VB default template? - I ask because unless i am mistaken what i've read thus far seems to focus more on adding code to PHP files. Currently running 4.1.10. The template I want to call from navbar template is called memberbar_basic. |
#215
|
|||
|
|||
Quote:
Code:
$templater = vB_Template::create('memberbar_basic');
$templater->register('my_var', $my_var); // one or more of these if memberbar_basic uses variables, otherwise leave it out.
$memberbar_basic = $templater->render();
vB_Template::preRegister('navbar', array('memberbar_basic' => $memberbar_basic));
and you would put {vb:raw memberbar_basic} in the navber template. Hook location parse_templates would probably be a good place for your plugin. |
#216
|
||||
|
||||
Hiya,
Thanks for responding - I can't seem to get it to work though, let me review whats currently configured. Template = memberbar_member_basic Template content = memberbar member basic test. Plugin name = memberbar_member_basic Plugin Hook = Parse Templates Plugin Content = PHP Code:
I tried moving {vb:raw memberbar_member_basic} to other templates, specifically forumhome but its still not rendering. would i have to use variables? if so, is there a guide/overview of what variables would bee needed anywhere? Thanks B |
#217
|
||||
|
||||
Off hand there's a typo in the middle line, it's missing the first "m" in "memberbar"
If that error is in your real code it wouldn't work. |
#218
|
||||
|
||||
haha, now i do really feel stupid....
ok, modified my thread correcting the typo and im please to say its working!.. /grabs coat.. (p.s. thank you!) --------------- Added [DATE]1330432890[/DATE] at [TIME]1330432890[/TIME] --------------- --------------- Added [DATE]1330432974[/DATE] at [TIME]1330432974[/TIME] --------------- Progressing from my previous query. I need to register some variables to allow notifications to be registered in my plugin (Post # 216) I've tried following this guide here.. https://www.vbulletin.com/forum/show...ons-menu-place I attempted the following, to no avail. Plugin name = memberbar_member_basic Plugin Hook = Parse Templates Plugin Content = PHP Code:
Code moved. PHP Code:
Thanks B |
Благодарность от: | ||
BirdOPrey5 |
#219
|
||||
|
||||
Progressing from my previous query.
I need to register some variables to allow notifications to be registered in my plugin (Post # 216) I've tried following this guide here.. https://www.vbulletin.com/forum/show...ons-menu-place I attempted the following, to no avail. Plugin name = memberbar_member_basic Plugin Hook = Parse Templates Plugin Content = PHP Code:
Code moved. PHP Code:
Thanks B |
#220
|
|||
|
|||
OK, I have done.
|
#221
|
|||
|
|||
PHP Code:
PHP Code:
PHP Code:
|
|
|
X vBulletin 3.8.12 by vBS Debug Information | |
---|---|
|
|
More Information | |
Template Usage:
Phrase Groups Available:
|
Included Files:
Hooks Called:
|