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 |
#202
|
|||
|
|||
If you switch the template names (just for a test), does it still only work in the navbar?
|
#203
|
||||
|
||||
Still not working, here is the complete code in use atm...
(code removed ) |
#204
|
|||
|
|||
Oh, that's different, I thought you were seeing nothing. But I think it's just that it should be vb:raw instead of vb.raw (I totally missed that in your above post).
|
#205
|
||||
|
||||
Lmao, wow! It was definately ":" instead of ".". I can't believe I did that . Thanks. [S]On a side note, any idea as to how to adjust the position of a Google+ button? I've been at it for several hours, and it just doesn't seem to move [/S] Figured that out finally
|
#206
|
|||
|
|||
i need help parsing a code into HEADER template using plugin
basically i need to insert a code after Code:
<div id="toplinks" class="toplinks"> using something like Code:
$find <div id="toplinks" class="toplinks"> $mycode <div style="float:right; margin: 5px -12px 5px 10px;">{vb:raw mycode </div> |
#207
|
||||
|
||||
Try this in the parse_templates hook:
Code:
require_once(DIR . '/includes/class_template_parser.php'); $parser = new vB_TemplateParser('<div id="toplinks" class="toplinks">'); $parser->dom_doc = new vB_DomDocument($parser->fetch_dom_compatible()); $find = trim($parser->_parse_nodes($parser->dom_doc->childNodes())); $parser = new vB_TemplateParser('<div style="float:right; margin: 5px -12px 5px 10px;">{vb:raw mycode}</div>'); $parser->dom_doc = new vB_DomDocument($parser->fetch_dom_compatible()); $replace = trim($parser->_parse_nodes($parser->dom_doc->childNodes())); $vbulletin->templatecache['header'] = str_replace($find, $find . $replace, $vbulletin->templatecache['header']); unset($find, $replace); |
#208
|
|||
|
|||
Quote:
I thank you very much it worked 100% updating templates this way works perfect without the need to go into the template to manually input it thx |
#209
|
||||
|
||||
You actually had doubts it would work?
|
#210
|
|||
|
|||
lol, i have lost touch with vb coding in a long time, i just need to get used to it, plus i am glad you repsonded i have seen your great work and advice on here
many thanks |
#211
|
||||
|
||||
vb 4 handles str_replace differently, for some reason. Glad I could help.
|
|
|
X vBulletin 3.8.12 by vBS Debug Information | |
---|---|
|
|
More Information | |
Template Usage:
Phrase Groups Available:
|
Included Files:
Hooks Called:
|