The first thing that has been is excessive eval, before in vBulletin 3 you would find eval peppered around the code everytime a template was being evaluated, this however has potential security implications and an overhead associated with it since none of the templates could be stored by opcode caches like APC and XCache.
vBulletin 4 now requires variables to be registered prior to their use within templates, previously all variables available at the time the template was rendered were available but this was known to cause problems when a variable was overwritten or not available. For the moment eval is still used to render the template but only inside the method in the class, this could potentially be removed in a future release.
The new code to render a template looks similar to below, while this may seem very verbose the registration method will allow more optimizations to be performed in the future.
PHP Code:
$templater = vB_Template::create('forumhome_event');
$templater->register('callink', $callink);
$templater->register('daysevents', $daysevents);
$templater->register('eventdate', $eventdate);
$templater->register('eventdates', $eventdates);
$upcomingevents = $templater->render();
Code:
<vb:if condition="$var == 2"> Value is 2 <vb:elseif condition="$var == 3" /> Value is 3 <vb:else /> Value is {vb:raw var} </vb:if>
Code:
<vb:each from="myarray" value="foo"> Hi {vb:raw foo} </vb:each>
Code:
<div class="someclass"> Output: Test <vb:comment> This won't be printed as comments are stripped at compile time. </vb:comment> </div>
Code:
<vb:literal> <vb:if condition="$var == 'test'"> Some test </vb:if> </vb:literal>
Dates can be formatted based on a timestamp, the second parameter indicates the format, if left blank the default board format is used.
Code:
{vb:date {vb:raw var}} {vb:date {vb:raw var}, Z} {vb:time {vb:raw var}} {vb:time H:i}
Code:
{vb:if 1+1 == 2, 'It does make 2', 'Ooops, maths fail!'}
Code:
{vb:number 1000.1234, 3}
Code:
{vb:phrase phrasename, {vb:raw var}, '<script>alert(document.cookie);'} {vb:rawphrase phrasename, {vb:raw var}, '<script>alert(document.cookie);'}
For variable access we have the regular kind, the raw variables and finally a short hand method.
Code:
{vb:var username} {$username}
Finally to complete the new syntax we are now offering more detailed error messages, when an invalid syntax is used we can tell the user what line this occurred and what was malformed.
Now for vB4 this doesn't work and I would like to know how to make it work with the new vb4 syntax. Thanks