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 |
#142
|
|||
|
|||
Quote:
|
#143
|
|||
|
|||
I've created a custom template "memberaction_dropdown_one" which I want to have show up in another custom template "postbit1".
Please help show me how to declare this. If anyone has skype it would be very much appreciated if you could walk me through the process in realtime (probably 5 min max). Send me a PM. |
#144
|
|||
|
|||
Just out of curiosity, is there any reason why this wouldn't work in vB 4.1.1? I'm getting some unexpected errors and wanted to rule out that element before I dig TOO deep.
Brandon |
#145
|
||||
|
||||
No, none that I'm aware of. This is pretty basic vB4 architecture, and nothing did change there.
|
#146
|
|||
|
|||
This is where one of those "thank you" mods would come in handy. This was a lifesaver, I was able to upgrade a mod that I needed for any upgrade.
|
#147
|
|||
|
|||
Is there any way to make plugin that uses remote database connection or use to extract data from other server?
We have vbulletin forum for our site, but our site is located on one server and forum located on another server in order to avoid load. I want to extract data from main site (which is located on another server) and display it on forum. I tried lot , searched everywhere. But I not found any specific plugin / mod. I created custom plugin on my own but it giving errors like "MySql client ran out of memory" "Invalid key error" |
#148
|
||||
|
||||
This is question has nothing to do with the article this discussion thread is for. Please open your own thread in an appropriate forum.
|
#149
|
||||
|
||||
I'm trying to capture a rendered/parsed template to a variable like so:
PHP Code:
Can anyone help me? |
#150
|
|||
|
|||
using in a mod:
1) make a new plugin Hook: global_start code: PHP Code:
also, tested and working in vb 4.1.2 also note that you can even make your own hook by using the code: HTML Code:
{vb:raw template_hook.hook_name} simple stuff. |
#151
|
||||
|
||||
Quote:
By the way: hook global_start is not a good choice. It does not exist in the CMS and will vanish from any part of the product that gets rewritten to the OOP framework in future. |
|
|
X vBulletin 3.8.12 by vBS Debug Information | |
---|---|
|
|
More Information | |
Template Usage:
Phrase Groups Available:
|
Included Files:
Hooks Called:
|