Go Back   vb.org Archive > vBulletin Article Depository > Read An Article > vBulletin 4 Articles

Reply
 
Thread Tools
vBulletin 4 Template Syntax: General
Marco van Herwaarden
Join Date: Jul 2004
Posts: 25,415

 

Show Printable Version Email this Page Subscription
Marco van Herwaarden Marco van Herwaarden is offline 08-22-2009, 10:00 PM

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

HTML Code:
{vb:var variable.foo} // accesses htmlspecialchars($variable['foo'])
{vb:var variable.$varkey} // accesses htmlspecialchars($variable[$varkey])
Raw Variables

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...]}
Inside curly braces, variables can be accessed without using a separate set of surrounding braces. For example,
HTML Code:
{vb:method {variable}} // unneccessary extra braces
HTML Code:
[font=Consolas]{vb:method variable}[/font]
Built-in Methods

phrase
HTML Code:
{vb:phrase phrase_name[, arguments for phrase...]}
Inserts the specified phrase. If arguments are provided, they will be run through htmlspecialchars.

rawphrase
HTML Code:
{vb:rawphrase phrase_name[, arguments for phrase...]}
As above, though arguments bypass htmlspecialchars.

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]}
Formats a UNIX timestamp using the default date format for the active language. A format may also be explicitly specified. Timezone will be corrected for the viewing user.

time
HTML Code:
{vb:time timestamp[, format]}
As above, though uses the default time format instead of date format.

number
HTML Code:
{vb:number number[, decimals]}
Outputs a number having run through vb_number_format for correct locale formatting. Number of decimal places to display can be optionally specified.

raw
HTML Code:
{vb:raw variable}
Outputs the variable raw, without any formatting or escaping.

escapejs
HTML Code:
{vb:escapejs variable}
Returns the variable prepared for use as a Javascript single-quoted string instead of running htmlspecialchars.

urlencode
HTML Code:
{vb:urlencode variable}
Escapes the variable using urlencode.

if
HTML Code:
{vb:if condition, true[, false]}
Use this in instances where the full <vb:if> tag can not be used, such as within HTML tags.

link
HTML Code:
{vb:link type, info[, extra-info]}
Used to build a hyperlink URL of the specified type and into the correct 'friendly' format.

math
HTML Code:
{vb:math expression}
Primarily used within CSS, this is used to evaluate the result of the mathematical expression specified.

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

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>
Any code inside vb:literal tags will be treated as plain HTML. No curly-brace syntax or vb:tag markup will be evaluated.

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

elseif
HTML Code:
<vb:elseif condition="condition" />true result
Used in conjunction with vb:if, this allows a secondary condition to be checked and the true result to be output if the condition is met.

else
HTML Code:
<vb:else />true result
Used in conjunction with vb:if, the true result will be output if the vb:if condition failed, and so did any vb:elseif checks.

comment
HTML Code:
<vb:comment>a comment</vb:comment>
In cases 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. Useful for internal commenting.

each
HTML Code:
<vb:each from="array" key="key" value="value"></vb:each>
This tag will iterate through an array, in a similar manner to foreach. See the example use below.

Example Use of vb:each

PHP Code:
// 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
Reply With Quote
  #2  
Old 08-23-2009, 02:55 PM
cellarius's Avatar
cellarius cellarius is offline
 
Join Date: Aug 2005
Posts: 1,987
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Some more verbose documentation of the new link-method would really be appreciated. For which types of pages is it operative, and what parameters can or have to be provided?
Reply With Quote
  #3  
Old 08-23-2009, 05:41 PM
Paul M's Avatar
Paul M Paul M is offline
 
Join Date: Sep 2004
Location: Nottingham, UK
Posts: 23,748
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Note that for "each" , the key part (in red) is optional.

Code:
<vb:each from="array" key="key" value="value">/*Do Something*/</vb:each>
Reply With Quote
  #4  
Old 12-24-2009, 03:49 PM
ragarcia87's Avatar
ragarcia87 ragarcia87 is offline
 
Join Date: Jun 2009
Location: Fort Smith
Posts: 65
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Has to be the worst template documentation ever. Basically this doc is a waste of time since there is soo little information in it. Not helpful what so ever, more of a hindrance since I wasted my time reading it instead of looking for a better resource. I would suggest you check out the Smarty template eninge's docs for what helpful docs look like.
Reply With Quote
  #5  
Old 12-26-2009, 07:14 PM
Antivirus's Avatar
Antivirus Antivirus is offline
 
Join Date: Sep 2004
Location: Black Lagoon
Posts: 1,090
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Thanks Marco for taking the time to write this for us. I found it quite helpful.
Reply With Quote
  #6  
Old 12-26-2009, 08:25 PM
Trek Trek is offline
 
Join Date: Sep 2003
Posts: 664
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by ragarcia87 View Post
Has to be the worst template documentation ever. Basically this doc is a waste of time since there is soo little information in it. Not helpful what so ever, more of a hindrance since I wasted my time reading it instead of looking for a better resource. I would suggest you check out the Smarty template eninge's docs for what helpful docs look like.
Feel free to write better documentation once you know what you're doing since you already know what good documentation is.

In the meantime, I found this helpful, thank you for writing it.
Reply With Quote
  #7  
Old 12-26-2009, 11:53 PM
ragarcia87's Avatar
ragarcia87 ragarcia87 is offline
 
Join Date: Jun 2009
Location: Fort Smith
Posts: 65
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by Trek View Post
Feel free to write better documentation once you know what you're doing since you already know what good documentation is.

In the meantime, I found this helpful, thank you for writing it.
Yea I would write helpful documention if they paid me, everyone here seems to forget this software costs money and has mabye 4 offical plugin + template docs released for a new plugin + template system compared to the likes of wordpress which is free and has more info than the average person will be able to take in.

Quote:
{vb:urlencode variable}
Yet no mention of what format the variable is to be used, is it the $variable or is it just variable.

Quote:
{vb:if condition, true[, false]}
No defination of the syntax for a condition, nor defination of what the out for true can be or how to format it. Same goes for

Quote:
<vb:if condition="condition">true result</vb:if>
which I personnally have extreme trouble getting to work, tried "$array.value='text'","array.text=text","$array.va lue==text",etc basically every way possible to try and get it to work and constantly it fails and which documention like this to fall back on it's a joke. If this was a user submitted documention it wouldn't bother me but it's offical documention and one of the few offical documention I could find, hell http://www.vbulletin.com/docs/ doesn't even have version 4 docs there. The only thing that eases my pain on this subject is knowing it wasn't me that paid for the license.
Reply With Quote
  #8  
Old 05-23-2010, 06:57 PM
mbreezy mbreezy is offline
 
Join Date: Feb 2007
Posts: 3
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I've tried multiple ways, but cannot seem to get it to output at all.

I'm trying to get some of the site stats variables from here to display, but to no avail.

I've tried a few ways...
PHP Code:
{vb:var totalthreads}
{
vb:var $totalthreads}
{
vb:raw totalthreads
Which combo is going to work?

Thanks
Reply With Quote
  #9  
Old 05-23-2010, 08:08 PM
cellarius's Avatar
cellarius cellarius is offline
 
Join Date: Aug 2005
Posts: 1,987
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

1 or 3, depending on what's in the variable. But I doubt that that variable is available in globally, so you'd probably make a plugin to fill it and register it for the template you want to use it in.
Reply With Quote
  #10  
Old 05-23-2010, 11:33 PM
mbreezy mbreezy is offline
 
Join Date: Feb 2007
Posts: 3
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Oh, okay. But I thought the variables listed in the vBulletin variable list (https://vborg.vbsupport.ru/showthread.php?t=179930) were global.
Reply With Quote
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 05:02 PM.


Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.09483 seconds
  • Memory Usage 2,336KB
  • Queries Executed 25 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)ad_showthread_beforeqr
  • (1)bbcode_code
  • (25)bbcode_html
  • (2)bbcode_php
  • (5)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)modsystem_article
  • (1)navbar
  • (4)navbar_link
  • (120)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (1)pagenav_pagelink
  • (10)post_thanks_box
  • (1)post_thanks_box_bit
  • (10)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (1)post_thanks_postbit
  • (10)post_thanks_postbit_info
  • (9)postbit
  • (10)postbit_onlinestatus
  • (10)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available:
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files:
  • ./showthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_post_thanks.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_postinfo_query
  • fetch_postinfo
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • forumjump
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • fetch_musername
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • post_thanks_function_fetch_thanks_bit_start
  • post_thanks_function_show_thanks_date_start
  • post_thanks_function_show_thanks_date_end
  • post_thanks_function_fetch_thanks_bit_end
  • post_thanks_function_fetch_post_thanks_template_start
  • post_thanks_function_fetch_post_thanks_template_end
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • pagenav_page
  • pagenav_complete
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete