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 |
#62
|
|||
|
|||
nvm figured it out
|
#63
|
||||
|
||||
I have read all posts and dont know how to call 3 templates in one page.
I have this code: PHP Code:
|
#64
|
|||
|
|||
I would fetch it before...
PHP Code:
F. |
#65
|
|||
|
|||
Thanks for this, hopefully i'll be able to know what to do.
|
#66
|
|||
|
|||
does anyone know how i can insert this into a template using plugin manager
to be placed in header Code:
function bb2_insert_head() { global $bb2_javascript; echo $bb2_javascript; } |
#67
|
||||
|
||||
n/m I figured I was missing $templater->render();
|
#68
|
|||
|
|||
I am not much of a coder at all, and hence need your help big time.
I want to call a simple php file to be placed just under the navbar. So, I created a plugin: Product: vBulletin Title: Insert Simple PHP Execution order: 5 (it was default) Hook Location: global_start PHP code: Code:
ob_start(); include('simple.php'); $insert_simple_php = ob_get_contents(); ob_end_clean(); Now, I went to the NAVBAR template and inserted Code:
{vb:raw insert_simple_php} Code:
{vb:raw ad_location.global_below_navbar} * Where does the 'register/pre-register' come? * What is the exact change I need to make here? Thanks for your help! |
#69
|
|||
|
|||
Great article!
but i have a problem. I have a template which i want to show inside another template, and it seems to work with every template except for the header. This is the plugin i used: PHP Code:
of course i have a template called TopPanel which i created, and it works great in vbcms_page for example but not in header. Do you have an idea why is that? Thanks in advance. |
#70
|
||||
|
||||
As the name suggests, the hook you use is called when vB-internal template processing is already completed. No use in preregistering templates then anymore. Since that hook did not exist in 4.0.1 as far as I can see, you're using 4.0.2. Another hook that got added in 4.02 is template_register_var, and that would be the right one to use.
|
#71
|
||||
|
||||
Quote:
PHP Code:
|
|
|
X vBulletin 3.8.12 by vBS Debug Information | |
---|---|
|
|
More Information | |
Template Usage:
Phrase Groups Available:
|
Included Files:
Hooks Called:
|