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 |
#112
|
|||
|
|||
It is related to this article? I'm asking how using what I found in this article i can do what others have clearly done since they said so in this thread. If you don't want to help me that's fine but since you helped others with there question to do with the footer I thought you might help me too silly me what was I thinking.
|
#113
|
||||
|
||||
oops, fixed it.
|
#114
|
|||
|
|||
I've tried following this example, but am having issues.
I am trying to get a custom template that was installed via an addon to show up in the header template. My plugin (uses the global_start hook): PHP Code:
PHP Code:
|
#115
|
|||
|
|||
To add a template in another with $template_hook add this plugin:
PHP Code:
PHP Code:
|
#116
|
||||
|
||||
Cellarius, this is an excellent article so I hope you may help me on my little issue. I read many threads and this article and I still cannot get aroudn to fix it.
In vB3 I had a simple plugin to display random banners on navbar template or parse_templates hook Code:
$random_number = mt_rand(1, 5); $random_banner[1] = '<img src="path/to/banner1.gif" alt="" border="0" />'; $random_banner[2] = '<img src="path/to/banner2.gif" alt="" border="0" />'; $random_banner[3] = '<img src="path/to/banner3.gif" alt="" border="0" />'; $random_banner[4] = '<img src="path/to/banner4.gif" alt="" border="0" />'; $random_banner[5] = '<img src="path/to/banner5.gif" alt="" border="0" />'; I posted my problem in this thread too. https://vborg.vbsupport.ru/showthread.php?t=249848 I hope you can help and thanks for your time. |
#117
|
||||
|
||||
You need to then preregister the array $random_banner for use in the navbar. Something like:
vB_Template:reRegister('navbar', array('random_banner' => $random_banner)); |
#118
|
||||
|
||||
Thank you very much Lynne,
I had to add a little bit more and actually change the plugin code to a simpler version. Inside the plugin I had to create a third variable $new_banners and only pre-registered that variable within template and ran it through parse_templates hook Quote:
For some (unknown) reason, {vb:raw random.banner.random_number} wasn't working as you suggested, although the arrays were set correctly. I appreciate your help and borbole for helping me through this. I hope other users find this little experience useful in their sites. |
#119
|
||||
|
||||
Quote:
|
#120
|
|||
|
|||
Just a small question,
i want to create a template that is showing above the header template.. do i need to register this template ? and how do i call this template above the header? its for a suite version of vB4.X |
#121
|
|||
|
|||
I asked this question over at the other VB forum and was directed to this article. Being completely new to all of this stuff and am still learning my way around, can someone please spell this out to me...
Quote:
|
Thread Tools | |
|
|
X vBulletin 3.8.12 by vBS Debug Information | |
---|---|
|
|
More Information | |
Template Usage:
Phrase Groups Available:
|
Included Files:
Hooks Called:
|