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 |
#172
|
|||
|
|||
Quote:
|
#173
|
||||
|
||||
What hook is your code on?
|
#174
|
|||
|
|||
what's a hook? I dont have a hook. I ended up just doing this. I basically just added my database code to the forum.php file and got it to work, but i have to modify every template like I mentioned in this thread, i'd rather use this thread https://vborg.vbsupport.ru/showthread.php?t=267120
|
#175
|
|||
|
|||
Quote:
See my post in the other thread. |
#176
|
|||
|
|||
First let me say that I am not PHP literate, but can find my way around 9 times out of 10.
I am creating custom templates to include my non vb scripts but am having troubles when trying to include a variable(?) from this script in any template outside the main body. I will try to be as detailed as possible, hopefully any responses will include the information I give as a real life example so that I can get an understanding of what was done. Goal: to take $companyname from the below script and add it to my page title, navbits etc. (currently I only get echos of $companyname or {vb:raw companyname}, depending on where I am in my efforts. PHP Code:
PHP Code:
PHP Code:
PHP Code:
Dave |
#177
|
||||
|
||||
I don't know if it's your only problem but you didn't register $companynanme in your webhost1.php file, so it won't show in your template.
|
#178
|
|||
|
|||
Could you dumb that down please?
|
#179
|
||||
|
||||
At the end of webhost1.php you have this code:
Code:
$templater = vB_Template::create('webhost-php'); $templater->register_page_templates(); $templater->register('navbar', $navbar); $templater->register('pagetitle', $pagetitle); $templater->register('sidebarext', $sidebarext); $templater->register('sidebaropen', $sidebaropen); $templater->register('headerincludea', $headerincludea); print_output($templater->render()); Code:
$templater = vB_Template::create('webhost-php'); $templater->register_page_templates(); $templater->register('navbar', $navbar); $templater->register('pagetitle', $pagetitle); $templater->register('sidebarext', $sidebarext); $templater->register('sidebaropen', $sidebaropen); $templater->register('headerincludea', $headerincludea); $templater->register('companynanme', $companynanme); print_output($templater->render()); |
#180
|
|||
|
|||
Thank you so much. As soon as I can put this paint brush down I will give it a shot.
Dave |
#181
|
|||
|
|||
Code:
$search_text = '<!-- end logged-in users -->'; $vbulletin->templatecache['FORUMHOME'] = str_replace($search_text, $search_text . fetch_template('forumhome_xyz'), $vbulletin->templatecache['FORUMHOME']); thank you |
Thread Tools | |
|
|
X vBulletin 3.8.12 by vBS Debug Information | |
---|---|
|
|
More Information | |
Template Usage:
Phrase Groups Available:
|
Included Files:
Hooks Called:
|