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 |
#192
|
||||
|
||||
LOL! That did it! It's always something simple I end up overlooking Thanks!
|
#193
|
|||
|
|||
Hi, I kinda only have a short question (before I waste another few days of my life, because I didn't wanted to ask for help lol).
My Problem is, that I would like to hook a template on {vb:raw header} (so I don't need any Template edits anymore). But all I get to work is, when I add in for example Forumhome Template {vb:raw header2} (then my template gets shown, but not if I try to use the real one). So the Question is: Is it actual possible or not (to use {vb:raw header})? The Plugin Code I am using: PHP Code:
And sorry for asking stupid Questions . |
#194
|
|||
|
|||
Sorry, you were trying to save a few days but it took a few days to get an answer.
But the answer is that it probably won't work because I think if 'header' gets registered somewhere else (which it probably is, just before the template is rendered), it will override what you pre-registered. |
#195
|
|||
|
|||
That's what I almost feared. So back to thinking how to get rid of the last template edit.
And thanks for the answer. |
#196
|
||||
|
||||
It may not be wise to use additional templates etc. just to get rid of a template edit. It adds considerable overhead.
|
#197
|
|||
|
|||
There is always 2 things to consider:
- the right way - the way people / customers and such prefer it (and thats usually no template edits :P) |
#198
|
|||
|
|||
I have been trying to do this for days, but ended up failing all the times. I have read this entire thread twice, from page 1-14 but still couldn't figure this out.
So I'm trying to change this part of showthread: I want to change it into my own moderation action instead of just closing the thread. I want to change the template with plug-in, but I couldn't get the right variable in which the informations about showthread quickreply are stored. On the early page of this thread, someone tried to change the footer just by accessing $footer .= "things to add"; on process_template_complete. So what variable should I be focusing on with my problem? I have already prepared a new template to replace that "checkbox", I just don't know how to access the existing template by using a plugin. Any help is appreciated.. |
#199
|
||||
|
||||
Ok, I'm obviously missing something, but not sure what. I'm trying to display a variable in the header template, and what I have works just fine in the navbar. Here's what I have to display my mod in the navbar (this works):
PHP Code:
PHP Code:
|
#200
|
||||
|
||||
What hook are you using? Header is rendered early, you may need a hook that is executed earlier.
|
#201
|
||||
|
||||
parse_templates
|
|
|
X vBulletin 3.8.12 by vBS Debug Information | |
---|---|
|
|
More Information | |
Template Usage:
Phrase Groups Available:
|
Included Files:
Hooks Called:
|