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 |
#222
|
||||
|
||||
Well, obviously $statar is an array. I have no idea how you set it up, but just as you can't do echo $array in PHP, you can't just use {vb:raw array}. In PHP you would do echo $array['key'] to output the value. In the template you need to use {vb:raw array.key} accordingly.
Just as described in the first chapter of the article. |
#223
|
|||
|
|||
Appreciate it Cellarius.
I looked through some of the other vbulletin, so I had to do something like. while yada yada { something = something['']} And everything started working. Mental error on my part. The only thing now is trying to complete a new mod for vbulletin. |
#224
|
|||
|
|||
If anyone is able to guide me, I am trying to hack the Post Thanks Plugin so I can pass a variable to a template as a conditional.
Here is the function I need to create a conditional for: PHP Code:
HTML Code:
<vb:if condition="$post['can_thank_post']">Button code here</vb:if> |
#225
|
|||
|
|||
LW (linkworth ) has given me a php file to include in the navigation bar. It will show rotating ads via rss feed. How can I include that file
I wrote the following code in global_start PHP Code:
Also the code in the rss_reader.php is : PHP Code:
|
#226
|
|||
|
|||
I'm just curious if registering the navbar is always necessary if you're creating a template for your own vB page, and if so, should the first post be updated to illustrate this?
And where the hell is the documentation on things like this: Quote:
|
#227
|
||||
|
||||
You won't stumble on to that anywhere in the files.
|
#228
|
|||
|
|||
|
#229
|
|||
|
|||
If I have this:
PHP Code:
Code:
{vb:raw my_array} Code:
Array
|
#230
|
||||
|
||||
{vb:raw my_array.0} = 1
{vb:raw my_array.1} = 2 |
#231
|
||||
|
||||
Quote:
PHP Code:
Quote:
|
|
|
X vBulletin 3.8.12 by vBS Debug Information | |
---|---|
|
|
More Information | |
Template Usage:
Phrase Groups Available:
|
Included Files:
Hooks Called:
|