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 |
#282
|
|||
|
|||
how to render avatar to custom page??
any idea? |
#283
|
||||
|
||||
I am trying to update a field I added to the thread table from a set of plugins that will be called whenever a post is edited or a new thread created. There is nothing to display. If the current post contains an image or an attachment, I want to copy the postid to my new field.
I think I need to preregister the node in the $thread array, but I am not sure how to do that. Can I freely reference an existing array in the preregister method? Here is the code I have now. The commented line is what I would expect the eventual sql statement to be. Code:
if (!$thread['thumbpostid']) //there is no thumbpost defined { if ((strpos($post['pagetext'], '[/IMG]') or ($post['attach']) ) // post has an attachment or there is an [img] tag { // $vbulletin->db->query_write("UPDATE ".TABLE_PREFIX."thread SET thumbpostid = ".$postid." WHERE threadid = ".$threadid); $threadman->setr('thumbpostid', $postid); } } |
#284
|
|||
|
|||
I'm currently working on an old vb addon to make it compatible to vb4.
Maybe somebody can help me with this following line: PHP Code:
PHP Code:
Thanks in advance. |
#285
|
|||
|
|||
I think you just need something like this:
PHP Code:
since the eval has been moved in to the vB_Template class. But if the template requires any variables, they now have to be registered. So it's likely you need something like: PHP Code:
|
#286
|
|||
|
|||
Thanks for your help.
That was exactly what i was looking for. |
#287
|
|||
|
|||
I should probably mention just in case, you don't have to register *every* variable because some standard vb ones are automatically registered, like bbuserinfo, style, show, vboptions, etc.
|
#288
|
|||
|
|||
I have to admit, this is going a bit beyond my scope of knowledge and I'm a bit lost.
I'm trying to place the same rotating banner ads in 4.2.2 that I currently use in 3.8.7 I've been told I need to register the templates and have been directed to this thread. I am certain the answer is here however I'm not grasping it. I currently run in house advertising via a table in the header that calls to plugins using the PHP random feature like this: In Table in header: Quote:
Quote:
Any help would be appreciated. |
#289
|
||||
|
||||
At the end of that plugin, you need to register that variable for use in the header template.
PHP Code:
|
#290
|
|||
|
|||
Just so I have this right before trying it and turning my vB install in to Pong game, in the Plug In PHP Code box I add that to the end like this:
PHP Code:
PHP Code:
|
#291
|
||||
|
||||
Did you try it? You really should have a test site set up so you can try this stuff before doing it on a live site.
|
|
|
X vBulletin 3.8.12 by vBS Debug Information | |
---|---|
|
|
More Information | |
Template Usage:
Phrase Groups Available:
|
Included Files:
Hooks Called:
|