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 |
#22
|
|||
|
|||
I figure out how to solve it:
hook: process_templates_complete code: $footer .= 'text added to footer'; No idea if was the best solution, but that worked very well. |
#23
|
||||
|
||||
Quote:
PHP Code:
Attachment 106372 Using str_replace, you can also add stuff in the middle of the template like so: PHP Code:
|
#24
|
|||
|
|||
Hi,
I'm trying to add something that requires PHP under the navbar. Back in vb 3.8.x I just used plugins for this. But, I'm not sure which hook to use if I want to display something under the navbar. |
#25
|
||||
|
||||
@David: This is not related to the topic of this article. You should open your own thread on this..
Also, I just added the bonus track about template caching. |
#26
|
|||
|
|||
Quote:
It's $cache[] = 'xxx'; and not $globaltemplate now |
#27
|
||||
|
||||
Ah, damn, of course you're right. I had my example code for vB3 and the one I was about to change for vB4 side by side and then obviously copied/pasted the wrong one. Stupid me
|
#28
|
|||
|
|||
Quote:
I made the mistake in all my add-ons on porting them to vB4 |
#29
|
|||
|
|||
Thanks for the "cache your templates" info, I made use of this info after making my own Terms of Service and Privacy custom pages, very helpful, thank you.:up:
|
#30
|
||||
|
||||
Quote:
<hookname>showthread_query</hookname> $vbulletin->templatecache['postbit'] = str_replace($find, $replace, $vbulletin->templatecache['postbit']); Also can this be used on variables? ex: {vb:raw variable} |
#31
|
|||
|
|||
This isn't working for me. I'm probably doing something wrong, but at the moment I have a custom php page (I created following another tutorial elsewhere) that is calling a custom template.
The code for the php page: PHP Code:
And the HTML template (called TESTPAGE): HTML Code:
{vb:stylevar htmldoctype} <html xmlns="http://www.w3.org/1999/xhtml" dir="{vb:stylevar textdirection}" lang="{vb:stylevar languagecode}" id="vbulletin_html"> <head> <title>{vb:raw vboptions.bbtitle}</title> {vb:raw headinclude} </head> <body> {vb:raw header} {vb:raw navbar} <div id="pagetitle"> <h1>{vb:raw pagetitle}</h1> </div> <h2 class="blockhead">Title</h2> <div class="blockbody"> <div class="blockrow"> Text </div> </div> {vb:raw footer} </body> </html> PHP Code:
Where have I gone wrong? I've spent a good half an hour going through the tutorial and trying various things but can't seem to get it working. It always makes the whole site blank, but if I call another template (e.g. contactus instead of TESTPAGE) it works fine, so the problem seems to lie with the plugin. Any help greatly appreciated - thanks in advance |
Thread Tools | |
|
|
X vBulletin 3.8.12 by vBS Debug Information | |
---|---|
|
|
More Information | |
Template Usage:
Phrase Groups Available:
|
Included Files:
Hooks Called:
|