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 |
#272
|
|||
|
|||
Links and Download Modification is stoped supported because the author is died
I have problem in vb 4.2.0 can't register the variables 1- plugins Name: Links and Downloads Manager - Add LDM to main vBulletin menu Hooks: Prosses_templates_complete code: PHP Code:
2- /includes/local_links_defns.php PHP Code:
PHP Code:
the problem Now , the variable is not registered like {vb:raw ldm_links_script} >> doesn't get the file name > thats make all links on the script ""when use the template" is invalid like this http://localhost/vb/.php // Links and Download Main links http://localhost/vb/.php?action=mod http://localhost/vb/.php?action=admin Please don't delete this post, the programer for this script will not help anymore, I searched alot to fix this problem but I can't fix it BTW: this problem only available in vb4.2.0 , and not present in 4.1.x , don't know what is the reason |
#273
|
|||
|
|||
Hopefully someone can help here... I am beginning the daunting task of upgrading from vb3.8 to vb4. My forumhome uses a variable "$forumbitcounter" which is calculated in a plugin which contains the following code:
Code:
$forumbitcounter++; |
#274
|
||||
|
||||
Quote:
PHP Code:
|
#275
|
|||
|
|||
Quote:
Also the variable is actually used in the forumhome_forumbit_level1_post template so would it need to be registered there or would registering it in the containing template be okay? |
#276
|
||||
|
||||
That code goes in the plugin right after your code that defines the variable. And if the variable is in the forumhome_forumbit_level1_post template template, then it needs to be:
PHP Code:
|
#277
|
|||
|
|||
Thanks Lynne got it to work... I tried to like your post but got a message saying I have to like someone else's before liking any more of yours lol.
--------------- Added [DATE]1365617230[/DATE] at [TIME]1365617230[/TIME] --------------- One other quick issue...I think this is due to the array (which I didn't have to use in vb3), the first value appears to be null, but needs to start with 1. How do I tell it to start with a value of 1? |
#278
|
||||
|
||||
I'm not sure I understand... what are you using in the template for the variable? It should just be $variable or {vb:raw variable}
|
#279
|
|||
|
|||
I found where is the problem, thanks
|
#280
|
|||
|
|||
Quote:
The problem seems to be on the first forumbitcount the value isn't 1 (I guess it is zero or is empty). Then the second forumbitcount is equal to 1 but should be 2. |
#281
|
||||
|
||||
The variable needs to get preregistered for use in the template *after* is it defined, just like I had posted it above:
PHP Code:
|
|
|
X vBulletin 3.8.12 by vBS Debug Information | |
---|---|
|
|
More Information | |
Template Usage:
Phrase Groups Available:
|
Included Files:
Hooks Called:
|