Template Syntax 
This topic contains reference and usage information about vBulletin template syntax.

Variable Access

Wherever possible, reference variables in templates using the following syntax:
{vb:var variable}
Variables accessed this way 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])
Raw Variables

To access variables in versions of vBulletin prior to V4, 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.

Curly-Brace Syntax

The general curly-brace syntax is the following:
{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}
Built-in Methods


The code {vb:phrase phrase_name[, arguments for phrase...]} inserts the specified phrase. If arguments are provided, they will be run through htmlspecialchars.

{vb:phrase welcome}

The code {vb:rawphrase phrase_name[, arguments for phrase...]} works like phrase, although arguments bypass htmlspecialchars.

{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}} 

The code {vb:date timestamp[, format]} formats a UNIX timestamp using the default date format for the active language. A format may also be explicitly specified. The timezone will be corrected for the viewing user.


The code {vb:time timestamp[, format]} works like date, although
it uses the default time format instead of date format.


The code {vb:number number[, decimals]} outputs a number having run through vb_number_format for the correct locale formatting. The number of decimal places to display can be optionally specified.


The code {vb:raw variable} outputs the variable raw, without any formatting or escaping.


The code {vb:escapejs variable} returns the variable prepared for use as a Javascript single-quoted string instead of running htmlspecialchars.


The code {vb:urlencode variable} escapes the variable using urlencode.


The code {vb:if condition, true[, false]} can be used in instances where the full <vb:if>[\var] tag cannot be used, such as within HTML tags.

<div class="{vb:if $forumid==1, forum1, forum}">...</div>

The code [var]{vb:link type, info[, extra-info]}
is used to build a hyperlink URL of the specified type and into the correct “friendly” format.

For more information, see <<<Insert doc link: Link Syntax>>>.


The code {vb:math expression} is primarily used within CSS to evaluate the result of the mathematical expression specified.

The code {vb:stylevar name[.sub-part]} is used to output a style variable from the style system. No escaping is performed.


All tags make use of the vb namespace for ease of identification and parsing.

The following tags are available.


The code inside <vb:literal>misc code</vb:literal> is treated as plain HTML. No curly-brace syntax or vb:tag markup is evaluated.


If the condition specified in <vb:if condition="condition">true result</vb:if> is true, the contents of the vb:if tags will be output, otherwise nothing will be output.

The following code is used in conjunction with vb:if.
<vb:elseif condition="condition" />true result
This allows a secondary condition to be checked and the true result to be output if the condition is met.
<vb:else />true result
Used in conjunction with vb:if, the true result is output if the vb:if condition failed, and so did any vb:elseif checks.


The code <vb:comment>a comment</vb:comment> is used where a comment is necessary but the usual <!-- 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. This is useful for internal commenting.


The code <vb:each from="array" key="key" value="value"></vb:each>
will iterate through an existing array, in a similar manner to foreach.

The following are example uses of <vb:each>.

// We have an array of users available in PHP. 
// It looks like this: 
// $users = array( 
//    1 => array('username' => 'Adam', 'email' => '[email protected]'), 
//    2 => array('username' => 'Ben', 'email' => '[email protected]'), 
//    3 => array('username' => 'Chris', 'email' => '[email protected]') 
// );  


<!-- 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>
<!-- 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>
Copyright © 2024 MH Sub I, LLC dba vBulletin. All rights reserved. vBulletin® is a registered trademark of MH Sub I, LLC dba vBulletin.