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 |
#262
|
||||
|
||||
What error are you getting?
|
#263
|
|||
|
|||
I don't know what exactly is the problem, in this case, is like the things aren't well connected. When i put hangman.php in 3.6, automatically add to the direction "?n=1" and if i clikc in the letters the program run well, but in 4 didn't do it. Also, in other plugin i have a button, but if i click it doesn't go to anywhere.
My question is: if you register a variable that doesn't have to be register, the php makes an error? I did this in the plugin: Code:
$templater = vB_Template::create('hangman'); $templater->register_page_templates(); $templater->register('hangmanwords', $hangmanwords); $templater->register('hangmanmax', $hangmanmax); $templater->register('hangmanguests', $hangmanguests); $templater->register('letters', $letters); $templater->register('n', $n); $templater->register('additional_letters', $additional_letters); $templater->register('words', $words); $templater->register('alpha', $alpha); $templater->register('all_letters', $all_letters); $templater->register('wrong', $wrong); $templater->register('word', $word); $templater->register('done', $done); $templater->register('word_line', $word_line); $templater->register('c', $c); $templater->register('links', $links); $templater->register('max', $max); $templater->register('x', $x); $templater->register('sorry', $sorry); $templater->register('play', $play); $templater->register('win', $win); $templater->register('term', $term); $templater->register('guess', $guess); $templater->register('nwrong', $nwrong); $templater->register('navbar', $navbar); $templater->register('pagetitle', $pagetitle); print_output($templater->render()); Sorry for my english, and thanks for your help. Also, the plugin, if you want to see it something more of the code is here: https://vborg.vbsupport.ru/showthrea...hlight=hangman |
#264
|
||||
|
||||
Can you post your hangman template code?
|
#265
|
|||
|
|||
Hi Lynne
The original template hangman: Code:
$stylevar[htmldoctype] <html dir="$stylevar[textdirection]" lang="$stylevar[languagecode]"> <html> <head> <meta name="description" content="$foruminfo[description]" /> <title>$vboptions[bbtitle] - $vbphrase[vb_hangman]</title> $headinclude </head> <body> $header $navbar <br> <table class="tborder" cellpadding="0" cellspacing="0" border="0" bgcolor="0" width="100%" align="center"><tr><td> <table cellpadding="$stylevar[cellpadding]" cellspacing="0" border="0" width="100%"> <tr id="cat"> <td bgcolor="{categorybackcolor}" colspan="5" class="tcat"><b> $vbphrase[vb_hangman]</b> </td> </tr> <table cellpadding="$stylevar[cellpadding]" cellspacing="$stylevar[cellspacing]" border="0" width="100%"> <td class="alt1"> <br> </div> <center> <p> <img src="images/hangman/hangman_$nwrong.gif" align="absmiddle" border="0" height="100" width="100" alt="Wrong: $wrong out of $max"> </p> $sorry $play $guess $win <br><br><br> </center> </tr> </td> <tr> <td class="tfoot"> </td> </tr> </table> </table> </td></tr></table> $footer </body> </html> Code:
{vb:stylevar htmldoctype} <html dir="{vb:stylevar textdirection}" lang="{vb:stylevar languagecode} id="vbulletin_html"> <html> <head> <title>{vb:raw vboptions.bbtitle} - {vb:raw pagetitle}</title> {vb:raw headinclude} </head> <body> {vb:raw header} {vb:raw navbar} <br> <table class="tborder" cellpadding="0" cellspacing="0" border="0" bgcolor="0" width="100%" align="center"><tr><td> <table cellpadding="{vb:stylevar cellpadding}" cellspacing="0" border="0" width="100%"> <tr id="cat"> <td bgcolor="{categorybackcolor}" colspan="5" class="tcat"><b> {vb:raw phrase vb_hangman}</b> </td> </tr> <table cellpadding="{vb:stylevar cellpadding}" cellspacing="{vb:stylevar cellspacing}" border="0" width="100%"> <td class="alt1"> <br> </div> <center> <p> <img src="images/hangman/hangman_{vb:raw nwrong}.gif" align="absmiddle" border="0" height="100" width="100" alt="Wrong: {vb:raw wrong} out of {vb:raw max}"> </p> {vb:raw sorry} {vb:raw play} {vb:raw guess} {vb:raw win} <br><br><br> </center> </tr> </td> <tr> <td class="tfoot"> </td> </tr> </table> </table> </td></tr></table> {vb:raw footer} </body> </html> |
#266
|
||||
|
||||
The template looks OK.... I don't see a link to the page so we can see exactly what is happening. Something can "not work" in so many different ways, so it would be good to see exactly what is going on with this one.
|
#267
|
|||
|
|||
Quote:
This is another plugin where i have, apparently, the same problem: The code is in the attached txt. Thank you for your help again. I reall apreciate always your help Lynne. |
#268
|
||||
|
||||
Registering a variable that doesn't need to be registered or is empty will NOT cause an error.
Are you just getting a blank white page when you try to view it? In that case look for your php error log (your host may be able to tell you how to view it) and see what errors are coming up after trying to view the blank page. |
#269
|
|||
|
|||
Quote:
Also i have another question of the use in the templates. For example, in the code that i put, in the old one appears like this: Code:
<vb:if condition="$stocktable != null"> --------------- Added [DATE]1356642316[/DATE] at [TIME]1356642316[/TIME] --------------- I solve the problem of the hangman. It seems like the PHP_SELF doesn't work in v4. Thanks to Lynne for the help. But i am working in the other one. My previous question to BirdOprey5 is about it. Lynne suspect that perhaps the problem is about javascript/ajax. ?Is different to v3 to v4? This is the code, if somebody knows that it is right or wrong: Code:
//----------------------------------------------------------------------------- // $Workfile: vbulletin_ajax_stocktrader.js $ $Revision: 1.4 $ $Author: addy $ // $Date: 2007/01/02 03:31:59 $ //----------------------------------------------------------------------------- var stock_xml; function handle_stock_lookup(symbol) { stock_xml = new vB_AJAX_Handler(true); stock_xml.onreadystatechange(handle_stock_lookup_response); stock_xml.send('vbtrade.php?do=lookup&symbol=' + symbol); return false; } function handle_stock_lookup_response() { if (stock_xml.handler.readyState == 4 && stock_xml.handler.status == 200) { if (stock_xml.handler.responseXML) { var response = stock_xml.fetch_data(fetch_tags(stock_xml.handler.responseXML, 'tag1')[0]); if (response != null) { var lookup_table = null; if (document.getElementById) lookup_table = document.getElementById('lookup_table'); if (lookup_table) lookup_table.innerHTML = response; } } } } |
#270
|
||||
|
||||
Code:
<vb:if condition="$stocktable != null"> I'm sorry I don't know anything about AJAX differences between VB3 and VB4. |
#271
|
|||
|
|||
Quote:
https://vborg.vbsupport.ru/showthrea...=242454&page=7 That variable "stocktable" must be registered in a plugin, but if i do it the forum dissapears. |
|
|
X vBulletin 3.8.12 by vBS Debug Information | |
---|---|
|
|
More Information | |
Template Usage:
Phrase Groups Available:
|
Included Files:
Hooks Called:
|