vBulletin 4.0 introduces a rich new syntax for marking-up templates, reducing the need for formatting and escaping to be performed in .php files.
Note that once a template makes use of any vBulletin 4 template syntax, the old syntax will cease to operate for that template. Conversions must be an all-or-nothing affair.
Going forward, variables should be referenced in templates wherever possible using the following syntax:
{vb:var variable}
Variables accessed in this manner are 'made safe' by being run through htmlspecialchars as they are output.
To access array elements, use a dot operator, rather than standard PHP square brackets:
{vb:var variable.foo} // accesses htmlspecialchars($variable['foo'])
{vb:var variable.$varkey} // accesses htmlspecialchars($variable[$varkey])
To access variables in the normal, pre-vB4 fashion, use the following syntax:
{vb:raw variable}
This is equivalent to simply accessing $variable in the pre-vB4 syntax. No treatment is applied to the variable. The same dot operator is used to access array elements.
The general syntax here is
{vb:method arg1[, arg2...]}
Inside curly braces, variables can be accessed without using a separate set of surrounding braces. For example,
{vb:method {variable}} // unneccessary extra braces
{vb:method variable}
{vb:phrase phrase_name[, arguments for phrase...]}{vb:rawphrase phrase_name[, arguments for phrase...]}
{vb:rawphrase message_by_x_on_y_at_z, {vb:link member, {vb:raw postinfo}}, {vb:raw postinfo.username}, {vb:raw postinfo.postdate}, {vb:raw postinfo.posttime}}
{vb:date timestamp[, format]}{vb:time timestamp[, format]}{vb:number number[, decimals]}{vb:raw variable}{vb:escapejs variable}{vb:urlencode variable}{vb:if condition, true[, false]}{vb:link type, info[, extra-info]}{vb:math expression}{vb:stylevar name[.sub-part]}All tags make use of the vb namespace for ease of identification and parsing.
The following tags are available:
<vb:literal>misc code</vb:literal>vb:literal tags will be treated as plain HTML. No curly-brace syntax or vb:tag markup will be evaluated.<vb:if condition="condition">true result</vb:if>vb:if tags will be output, otherwise nothing will be output.<vb:elseif condition="condition" />true resultvb:if, this allows a secondary condition to be checked and the true result to be output if the condition is met.<vb:else />true resultvb:if, the true result will be output if the vb:if condition failed, and so did any vb:elseif checks.<vb:comment>a comment</vb:comment><!-- comment --> syntax is undesirable, the vb:comment tag allows its contents to be completely removed upon compiling, so they will not be delivered to the browser. Useful for internal commenting.<vb:each from="array" key="key" value="value"></vb:each>// We have an array of users available in PHP.
// It looks like this:
// $users = array(
// 1 => array('username' => 'Adam', 'email' => 'adam@adam.com'),
// 2 => array('username' => 'Ben', 'email' => 'ben@ben.com'),
// 3 => array('username' => 'Chris', 'email' => 'chris@chris.com')
// );
<!-- our template code... -->
<vb:each from="users" key="userid" value="userinfo">
<li><a href="member.php?u={vb:var userid}">{vb:var userinfo.username}</a></li>
</vb:each>
<!-- will output... -->
<li><a href="member.php?u=1">Adam</a></li>
<li><a href="member.php?u=2">Ben</a></li>
<li><a href="member.php?u=3">Chris</a></li>