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 |
#132
|
||||
|
||||
thanks for the time and effort spent on this article
very helpfull |
#133
|
||||
|
||||
Please help me with this issue.
I have a plug in (Location: parse_templates) Code:
if($vbulletin->options['enable_vbadv'] AND in_array($vbulletin->userinfo['usergroupid'], explode(',', $vbulletin->options['vbadv_ug']))) { switch($vbulletin->options['vbadv_place']) { case 1: $place = '$navbar'; $fechttemplate = 'FORUMHOME'; break; case 2: $place = '$ad_location[ad_navbar_below]'; $fechttemplate = 'navbar'; break; default: $place = '$navbar'; $fechttemplate = 'FORUMHOME'; break; } $vbulletin->templatecache[$fechttemplate] = str_replace($place, $place . '\n' . fetch_template('forumhome_+++++++_com_adv'), $vbulletin->templatecache[$fechttemplate]); } I've tried to fix it like this Code:
if($vbulletin->options['enable_vbadv'] AND in_array($vbulletin->userinfo['usergroupid'], explode(',', $vbulletin->options['vbadv_ug']))) { $templater = vB_Template::create('forumhome_+++++++_com_adv'); $templater->register('advheader', $advheader); $advheader = $templater->render(); switch($vbulletin->options['vbadv_place']) { case 1: $template_hook['forumhome_above_forums'] .= $advheader; break; case 2: $ad_location['global_below_navbar'] .= $advheader; break; } } Thank you very much, and sorry for my bad English. --------------- Added [DATE]1293914180[/DATE] at [TIME]1293914180[/TIME] --------------- It's Fixed. Just simple change Location to "global_start" |
#134
|
|||
|
|||
All I want to do is covert the current fetch template into current VB code. How do I do this in 4.0?
Code:
eval('$soundnotification = "' . fetch_template('sound_notification') . '";'); Code:
$soundnotification .= vB_Template::create('sound_notification')->render(); |
#135
|
|||
|
|||
is posible to do
{vb:raw my_var.userid} or how i should call for the user id or username? for example vb3: <br>User Registration IP Address: $spammerinfo[ipaddress] <br>User IP Address for Selected Post: $postinfo[ipaddress] but how to make it work for vb4? :S |
#136
|
||||
|
||||
Quote:
{vb:raw spammerinfo.ipaddress} {vb:raw postinfo.ipaddress} |
#137
|
|||
|
|||
uhmm yeah, but the problem is that spammerinfo attribute is not working :S
|
#138
|
||||
|
||||
Did you register the variable for use in that template?
|
#139
|
|||
|
|||
Quote:
|
#140
|
|||
|
|||
I want to register $forum in facebook_publishcheckbox template. But I don't know where I set those set those register value in what file.
PHP Code:
facebook_publishcheckbox Template Code:
<label id="fb_pulishlabel" for="fb_dopublish"> <img src="{vb:stylevar imgdir_misc}/facebook.gif" alt="{vb:rawphrase publish_to_facebook}" /> {vb:rawphrase publish_to_facebook} <input type="checkbox" tabindex="1" id="fb_dopublish" value="1" <vb:if condition="in_array($forum['forumid'], array(70,80,81,82,83,88,92,93))"><vb:else />checked="checked" </vb:if>name="fb_dopublish" /> </label> |
#141
|
||||
|
||||
Put the register code in a plugin, and call it where your template displays (by choosing hook location). In the case you don't really know what to do, Creat a new plugin and choose hook location is global_start or parse_template
|
|
|
X vBulletin 3.8.12 by vBS Debug Information | |
---|---|
|
|
More Information | |
Template Usage:
Phrase Groups Available:
|
Included Files:
Hooks Called:
|