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 |
#72
|
|||
|
|||
cellarius & moonray - you are both stars!!!
Thanks you! Al |
#73
|
|||
|
|||
FINAL WORKING CODE:
Product: vBulletin Title: Insert Simple PHP Execution order: 5 Hook Location: global_start PHP code: Code:
ob_start();
include('simple.php');
$simple_php = ob_get_contents();
ob_end_clean();
vB_Template::preRegister('navbar',array('simple_php' => $simple_php));
Now, go to the NAVBAR template and insert Code:
{vb:raw insert_simple_php} Code:
{vb:raw ad_location.global_below_navbar} |
#74
|
||||
|
||||
I'm hoping someone can help me.. I'm having trouble displaying Openx Ads in various locations. For example in the header template.
This is the php code that Openx generates: PHP Code:
PHP Code:
|
#75
|
||||
|
||||
No comments on my last post?
|
#76
|
|||
|
|||
This is what I'm using.
PHP Code:
|
#77
|
||||
|
||||
Thank you very much WAJones!! That works great! :up: :up: :up:
|
#78
|
||||
|
||||
Guys help me to update this hack to vB 4
https://vborg.vbsupport.ru/misc.php?...t_post_only_37 I cant show the message "register...." to guests: PHP Code:
|
#79
|
|||
|
|||
Great article!
I have a question. In vB3, you could do this: PHP Code:
|
#80
|
||||
|
||||
Quote:
|
#81
|
||||
|
||||
I'm trying to append some text to the end of the footer.. in a plugin.. but I'm totally lost.
How do I get the footer out of the cache to append some text to it? |
|
|
X vBulletin 3.8.12 by vBS Debug Information | |
---|---|
|
|
More Information | |
Template Usage:
Phrase Groups Available:
|
Included Files:
Hooks Called:
|