vBulletin 4 Template Syntax: General
by
23 Aug 2009
The content of this article is also available in your vBulletin distribution in ./readme-syntax.html. vBulletin 4 Template Syntax 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. Variable Access Safe Variables Going forward, variables should be referenced in templates wherever possible using the following syntax: HTML Code:
{vb:var variable} To access array elements, use a dot operator, rather than standard PHP square brackets: HTML Code:
{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: HTML Code:
{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 syntax here is HTML Code:
{vb:method arg1[, arg2...]} HTML Code:
{vb:method {variable}} // unneccessary extra braces HTML Code:
[font=Consolas]{vb:method variable}[/font] phrase HTML Code:
{vb:phrase phrase_name[, arguments for phrase...]} rawphrase HTML Code:
{vb:rawphrase phrase_name[, arguments for phrase...]} Example: HTML Code:
{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}} date HTML Code:
{vb:date timestamp[, format]} time HTML Code:
{vb:time timestamp[, format]} number HTML Code:
{vb:number number[, decimals]} raw HTML Code:
{vb:raw variable} escapejs HTML Code:
{vb:escapejs variable} urlencode HTML Code:
{vb:urlencode variable} if HTML Code:
{vb:if condition, true[, false]} link HTML Code:
{vb:link type, info[, extra-info]} math HTML Code:
{vb:math expression} stylevar HTML Code:
{vb:stylevar name[.sub-part]} Tags All tags make use of the vb namespace for ease of identification and parsing. The following tags are available: literal HTML Code:
<vb:literal>misc code</vb:literal> if HTML Code:
<vb:if condition="condition">true result</vb:if> elseif HTML Code:
<vb:elseif condition="condition" />true result
else HTML Code:
<vb:else />true result
comment HTML Code:
<vb:comment>a comment</vb:comment> each HTML Code:
<vb:each from="array" key="key" value="value"></vb:each> Example Use of vb:each PHP Code:
// We have an array of users available in PHP.
|