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 |
#92
|
|||
|
|||
This is a great thread and I know I'm on the right track.
I am trying to add a custom profile field to the memberaction_dropdown template. {vb:raw post.field5} How would I register this to work in the memberaction_dropdown? It works on postbit (because I'm assuming it is registered) Thanks again for a great write-up! |
#93
|
||||
|
||||
Quote:
thanks anyway for your time mate to reply on this... best regards... |
#94
|
|||
|
|||
i want to do that some codes work in navbar template but same code dont work in header or navbar . for example how can i run vb:raw forum.title} in forumhome.lastpostinfo template ?
|
#95
|
|||
|
|||
i'm a little confused on how to get my loops into the templates.
how would i get mypage.php: Code:
while ($result = $db->fetch_array($results)){ $something .= $result['field1']; $something2 .= $result['field2']; } $templater->register('something ', $something ); Code:
<ul> START TO DISPLAY LOOPED DATA <li> {vb:raw something} </li> END TO DISPLAY LOOPED DATA </ul> |
#96
|
|||
|
|||
I've been trying like crazy... We need more turorials...
@ vB staff: RTFM should be WTFM |
#97
|
||||
|
||||
Quote:
Quote:
$templater->register('navbits', $navbits); |
#98
|
|||
|
|||
Thanks a bunch for the reply
Would this be needed to be doing in the hook location where it starts creating the footer ? And in the case of the footer template, which has no hook-location, which hook location is best used ? Quote:
And if the navbar template was built after the footer, in which hook-location would I need to pre-register the $navbits ? Thanks ! |
#99
|
|||
|
|||
as far as I have seen, footer template is created at the moment any other template is done...
example: if at the top of a file.. before you did any template stuff... you do PHP Code:
but if you do: PHP Code:
--> so just find a place before the first template is created... Felix |
#100
|
|||
|
|||
Please can somebody help, I just can't figure out what I'm doing wrong.
I'm trying to add to FORUMHOME and I can't get the basic example working. I've created a new plugin (hook: forumhome_start) with the following PHP code: PHP Code:
PHP Code:
Am I right in expecting <p>abc</p> to appear in my forum home page source? Because I just get empty <p></p>, i.e. the variable doesn't exist. I've tried different hook locations. I also tested the forumhome_start location by adding an "echo 'abc'; in the plugin php, and as expected "abc" appears right at the top of my forum home source. What am I doing wrong? :S EDIT!:: Apologies, missed this post: https://vborg.vbsupport.ru/showpost....1&postcount=72 |
#101
|
||||
|
||||
As you wrote it you should use my_var first in template mytemplate.
Then when you use <p>{vb:raw my_insertvar}</p> in FORUMHOME all content from mytemplate will be appear. |
|
|
X vBulletin 3.8.12 by vBS Debug Information | |
---|---|
|
|
More Information | |
Template Usage:
Phrase Groups Available:
|
Included Files:
Hooks Called:
|