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 |
#122
|
||||
|
||||
You need to find out in the php files where the quickchooserbits and languagechooserbits variables are filled; they also will be registered for the footer template there. Then you need to find a hook that's executed afterwards and register those two variables for the template you want to put it in.
|
#123
|
|||
|
|||
Quote:
Does this come in english? O.o Sorry, but I am VERY new to all of this due to necessity and am not familiar with some of the terminology yet. Where do I look for the PHP files? How do I register variables? How do I find/register a hook? |
#124
|
||||
|
||||
The php files (among other stuff) is what you upload to your webspace. How to register variables for templates is what this tutorial is all about, but if you don't have at least basic knowledge of php this may be difficult to do.
Some basics about the vB addon/plugin system can be found here: http://www.vbulletin.com/docs/html/ |
#125
|
|||
|
|||
Thanks for that. I may be getting over excited with wanting to do stuff now that I can. I will definately read up some more. I have found (bluffed) my way through a lot relatively unscathed so far.
Quick hint: Do I look int the FTP or ACP? Ta |
#126
|
||||
|
||||
PHP files you find via FTP, plugins and addons you handle via AdminCP.
|
#127
|
|||
|
|||
I am using a custom page and it works properly. However, I have listed on the custom page in the style editor {vb:raw navbar2}. I want the template to display what is in my navbar2 style.
This is in the php file for the custom page: $templater = vB_Template::create('ncsu'); $templater->register_page_templates(); $templater->register('navbar', $navbar); $templater->register('navbar2', $navbar2); $templater->register('pagetitle', $pagetitle); print_output($templater->render()); And it is still not recognizing {vb:raw navbar2}. Should I add something about this? If so, what? Thank you! |
#128
|
|||
|
|||
Okay guys, I have read the entire thread and my apologies for my coding ignorance. What I am trying to do is, use a different navbar template on the forumdisplay pages than on the home page.
So I added a new template, called navbarforumdisplay Copied the code from the navbar template into navbarforumdisplay and removed the items I added in the forumhome version that I don't want appearing in the forumdisplay (only items I added to begin with, not vB code ). Then after reading this thread, I created a plugin here Title: Forumdisplay Navbar Hook Location: forumdisplay_complete Exc Order: 5 with the following code Code:
global $template_hook; $newTemplate = vB_Template::create('navbarforumdisplay'); $template_hook['fd_navbar'] .= $newTemplate->render() Code:
{vb:raw fd_navbar} Code:
{vb:raw navbar} Thank you!!! |
#129
|
|||
|
|||
could anybody please give me a step by step tutorial, how to make this code work in postbit_legacy?
PHP Code:
|
#130
|
||||
|
||||
Waaaay too complicated. Go to the normal navbar template and put everything you do not want to appear on forumdisplay inside this condition:
Code:
<vb:if condition="THIS_SCRIPT != 'forumdisplay'">code not to be shown on forumdisplay</vb:if> |
#131
|
||||
|
||||
Hello. I need your help.
I need the $pagenumber variable to be available in postbit_legacy so that I can create an url when the thread has multiple pages. Currently I am using: <a href="http://www.patientenfragen.net/{vb:link thread, {vb:raw thread}}" target="_blank"> but I need it to work this way: <a href="http://www.patientenfragen.net/{vb:link thread, {vb:raw thread}<vb:if condition="$pagenumber">&page={vb:raw pagenumber}</vb:if>}" target="_blank"> I need the url including the page the user is on. I am no programmer so even though your explanation is quite detailed I don't really get what I have to do. I need to register that variable to the postbit_legacy template, but how do I do that? Sorry for asking such a stupid question but I am totally lost here. Any help is much appreciated. StarBuG |
|
|
X vBulletin 3.8.12 by vBS Debug Information | |
---|---|
|
|
More Information | |
Template Usage:
Phrase Groups Available:
|
Included Files:
Hooks Called:
|