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 |
#52
|
|||
|
|||
I still cannot figure out how in the heck to work this new template system.
Code:
eval('$awarduserslist .= ", ' . fetch_template('awards_awardusers_bit') . '";'); However Code:
$displayTemplate = vB_Template::create('awards_awardusers_bit'); $awarduserslist .= $displayTemplate->render(); |
#53
|
|||
|
|||
Thanks for this guide, at the beginning I was totally confused about this new system.
On the other hand, is there a system to preregister a var in all templates with a single call? |
#54
|
|||
|
|||
Thanks for the guide
|
#55
|
||||
|
||||
@ cellarius
Absolutly a great introduction how things now working on VB4. It answere`s many questions to me now. I just wanne thank you cellarius for this. btw. many thanks to Lynne who also allways help out. i`m absolutly new to stuff like "vb" or "php" but with your "helping hand`s" alot of work is possible to do for me too. Sorry about my englisch, its not "my one" Thanks again an enjoy the hollydays ...... if there some ........ |
#56
|
||||
|
||||
I have question:
How to change content of existing template inside of plugin? I'm remaking my mod for vB4. I'm adding there flags to header of footer. In vB3 version I simply change insides of template using templatecache. I.e.: PHP Code:
How to change this line of code to make it working in vB4? EDIT: Ok - I already found it here Now check if its working :P --------------- Added [DATE]1262746169[/DATE] at [TIME]1262746169[/TIME] --------------- Other question: In vB3 my mod have possibility to put additional data in custom place - so user just manually adds variable into required template and he has flags where he put it. How to do this in vB4 where variables have to be preregistered????... --------------- Added [DATE]1262746545[/DATE] at [TIME]1262746545[/TIME] --------------- Quote:
Also this solution is working on already parsed template - I need fresh one, not parsed yet. Anyone have idea how to do that? EDIT Ok I have it need to use hook parse_templates |
#57
|
|||
|
|||
Awesome guide. It has helped me move forward a bit, but I still don't have it all down yet. If anyone has this down pat, I'd be interested in some more tutorials that show old 3.x code and then below shows the 4.x code. This way I can test myself and see how well I have it down.
In the meantime though, is the new rendering needed for redirects? For example: Code:
$vbulletin->url = "misc.php?do=editform&fid=$fid"; eval(print_standard_redirect('redirect_insertform', true)); Code:
$templater = vB_Template::create('redirect_insertform'); $templater->register_page_templates(); $templater->register('redirect', $vbulletin->url); print_standard_redirect($templater->render()); |
#58
|
||||
|
||||
No, standard redirects and errors still work the old way. If you want to know something like that, just look one up in the original vB4 php files.
|
#59
|
||||
|
||||
I have a template that I need to insert into multiple pre-existing templates (I add some additional graphics/formatting to the header and footer of most tables ... and my CSS skills aren't good enough to achieve what I'm trying to do through CSS alone, so I need to add old HTML table coding). I do it this way so that if I want to make changes, I don't have to change lots of different templates. After a bit of struggling, I have managed to get the following code running.
Code:
$templater = vB_Template::create('layout_start'); $templater->register('my_var', $my_var); $templatevalues['start_insertvar'] = $templater->render(); vB_Template::preRegister('FORUMHOME', $templatevalues); I have two questions. Is there any way to preRegister for more than one pre-existing template (or a global registration), or do I have to create Plugins for every page I want to add this to (*groan*)? And what is the best hook to have this on. I am currently using 'parse_templates'. The other unusual thing I'm finding happening is if I include my template in postbit_legacy, it will show on the first post, but not on the posts after that. Thanks in advance... |
#60
|
||||
|
||||
Quote:
Code:
$templater = vB_Template::create('layout_start'); $templater->register('my_var', $my_var); $templatevalues['start_insertvar'] = $templater->render(); vB_Template::preRegister('FORUMHOME', $templatevalues); vB_Template::preRegister('SHOWTHREAD', $templatevalues); vB_Template::preRegister('FORUMDISPLAY', $templatevalues); Code:
$templater = vB_Template::create('layout_start'); $templater->register('my_var', $my_var); $start_insertvar = $templater->render(); $templatevalues['start_insertvar'] = $start_insertvar; vB_Template::preRegister('FORUMHOME', $templatevalues); $templatevalues['start_insertvar'] = $start_insertvar; vB_Template::preRegister('SHOWTHREAD', $templatevalues); $templatevalues['start_insertvar'] = $start_insertvar; vB_Template::preRegister('FORUMDISPLAY', $templatevalues); Quote:
|
#61
|
|||
|
|||
...
|
|
|
X vBulletin 3.8.12 by vBS Debug Information | |
---|---|
|
|
More Information | |
Template Usage:
Phrase Groups Available:
|
Included Files:
Hooks Called:
|