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 |
#292
|
|||
|
|||
I do have a test site up with a separate database and vB install on it for testing prior to trying anything on my live forum.
You'll have to excuse my manner of asking follow up questions, when I can't get something to work I tend to ask questions in the form of clarification of what I am doing assuming I have made an error rather than saying 'that didn't work'. It seems more respectful of those trying to help. The comment about roasting my vB install is mostly comedy however I did manage to do something to my test install when I first tried to make the ad banners work that killed it and required a wipe and reinstall. So far I have not been able to get the random banners to display, all I have gotten is the header code displaying above the title. I have placed the header code in various places within the header template and have placed the registration code at the very end of the plug in as above and tried it as the second line of the plug in. All with the same results, I can only assume that I am missing a step somewhere. |
#293
|
||||
|
||||
I couldn't tell from your post whether you were asking for help or not. But, I did just notice that you have the variable entered wrong in your template (that's what happens when you look at vB3 and vB4 and vB5 sites all the time!). It's
{vb:raw random_banner11['$random_number11']} And, I didn't notice you had two variables - you need to register each of them. |
#294
|
||||
|
||||
The first post shows you how to register a variable here:
PHP Code:
|
#295
|
||||
|
||||
No, you can add it to a plugin. If you are using it on every page, then you'll want to use a hook location that is on every page - maybe one of the global_* ones. You'll have to try it and see which works best.
|
Благодарность от: | ||
#296
|
|||
|
|||
Hi,
I understand above all things. I just wanted to know that, {vb:raw user.username} above code I found in template 'header'. From where this header template gets object 'user' and how it can able to access it property. I am interested know where this vBulletin variable like 'user' stored and in which php file? Can any one help me to understand this? Thanks!!!! |
#297
|
||||
|
||||
Quote:
|
#298
|
||||
|
||||
Any suggestion why the code below does not works as expected?
PHP Code:
EDIT: What I was adding in the templates is: {vb:raw mybanners} |
#299
|
|||
|
|||
I would use hook parse_templates. You say you've tried "many different templates", do you mean other hean 'header'? Of course you know, but double check that you put {vb:raw mybanners} in the same template that you preRegister() to.
|
Благодарность от: | ||
TheAdminMarket |
#300
|
||||
|
||||
Quote:
--------------- Added [DATE]1422806090[/DATE] at [TIME]1422806090[/TIME] --------------- That did the trick. Thank you. |
#301
|
|||
|
|||
hock process_templates_complete
PHP Code:
|
|
|
X vBulletin 3.8.12 by vBS Debug Information | |
---|---|
|
|
More Information | |
Template Usage:
Phrase Groups Available:
|
Included Files:
Hooks Called:
|