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 |
#102
|
||||
|
||||
Just wanted to thank Cellarius for this very useful article. Thanks Mate...
|
#103
|
|||
|
|||
Where exactly do I write this content? This part is quite complicated
|
#104
|
|||
|
|||
Hello, I hope someone can point in the right direction. I'm trying to port a mod to vb4 which has a number of templates. The php file contains a whole bunch of
Code:
eval('$template .= "' . fetch_template('templatename') . '";'); I've tried a number of different iterations form the first post but I can't get anything but the main template to render. How does one go about making something like this work? thanks. |
#105
|
|||
|
|||
nevermind. Turns out I had numerous typos.
Now I'm running into a different problem. I'm editing a (sub)template which is rendered in a variable in the php file and called using: Code:
{vb:raw display_map} Code:
Warning: Invalid argument supplied for foreach() in [path]/includes/functions.php on line 3332 Any suggestions where the problem might be? It doesn't seem to matter where I put the variable reference. If there is {vb:raw variable} in the template it won't save. |
#106
|
|||
|
|||
Quote:
|
#107
|
|||
|
|||
Quote:
Bob |
#108
|
|||
|
|||
I'm working to insert my own VAR into an existing template. I've seen the examples saying to use vb_Template:reRegister. However I have a catch...I'm using a cloned copy of an existing template. For example, I cloned the default style -- and created newStyle. Then within newStyle, I modified postbit_legacy and would like to display my own $var within the cloned copy of postbit_legacy.
Questions: 1. How to register/preRegister into a cloned template (newStyle->postbit_legacy). 2. How to properly use preRegister -- if that's what's needed. My data isn't an array, and preRegister only works with arrays. |
#109
|
||||
|
||||
If you're creating a new style based on another one (in this case the default style), the template name is still postbit_legacy and the template itself still is template legacy. Doesn't matter at all.
If you're variable is not an array, make it an array. $templatevalues['myvariable'] = $myvariable. |
#110
|
|||
|
|||
Could you please point me in the right direction as to how I might add an extra field in newthread template, I was trying to do it automatically with the product install and I read here about using process_template hook and str_replace but Im still a little confused by it any help on this greatly appreciated.
|
#111
|
||||
|
||||
Please open your own thread for questions not directly related to this article.
|
|
|
X vBulletin 3.8.12 by vBS Debug Information | |
---|---|
|
|
More Information | |
Template Usage:
Phrase Groups Available:
|
Included Files:
Hooks Called:
|