WebvantaScript Cheat Sheet

Page Info

<w:meta:title />

Provides metadata title for the current page.

<w:meta />

Produces meta description and keyword tags for current page. A shortcut that is equivalent to <w:meta:keywords /><w:meta:description />.

<w:url />

Provides full slug for the current page (not really the full URL, since it does not include http:// or the domain name).

<w:default_label />

Provides the label for the page, as set in the page admin.

<w:content region="region_name" />

Inserts an editable page region; used in templates only.

<w:meta:description />

Provides the description for the current page. By default, it also creates the description meta tag.

<w:meta:keywords />

Provides the keywords for the current page. By default, it also creates the keywords meta tag.

Page Hierarchy

<w:children:each >

Iterate through each of the child pages (subpages) of the current page.

<w:parent />

Access the page that is the parent of the current page.

<w:siblings:each>

Iterate through each of the siblings of the current page (other subpages of this page's parent).

<w:if_first>

Include following code if current page is the first in a set of subpages.

<w:if_ancestor_or_self>

Include the following code if the current contextual page is either the currently displayed page, or one of its parents.

<w:if_children>

Include the following code only if the current page has children.

<w:if_last>

Include following code only if current page is the last in a set of subpages.

Item Iterators

<w:kb:item:each condition="any condition">

Iterate through items that meet the specified condition.

<w:kb:item:each>

Iterate through a set of database items that has been previously set by the context.

<w:kb:item:each filter="current_item">

Iterate through a set of items, excluding the current item on the page. Used for showing related content.

<w:kb:item:paginate limit="items-per-page">

The same as item:each, except that the results are paginated. See example for details.

<w:kb:item:comments:each (options)>

Iterate through each of the comments on the current item. See examples for options and field names.

<w:kb:item:iterator_size>

Returns the total size of the current iterator's items count, after any conditions are applied. Note that if you only need the size, and don't need to actually return all the items, iterator_preflight_size is much faster.

<w:if_each_index condition="operator number">

Tests the current loop index using the specified condition. "operator" is a standard conditional comparison, such as ==, >, <, !=

<w:each_index>

For use inside an "each" iterator, such as w:kb:item:each or w:taxonomy:each; returns the number of the current index, starting at 0 for the first iteration.

<w:kb:item:iterator_preflight_size />

Pass in the same attributes you would use in kb:item:each and this statement will return how many items would be returned if you did the actual iteration.

Assets (Images & other files)

<w:assets:each taxonomy="tax:term">

Iterate through all of the assets that are assigned to the specified taxonomy term. See examples for options.

<w:kb:item:icon rendition='thumb' />

Access the icon associated with the current item. Returns the path to the image file, optionally in the specified rendition.

<w:asset name="/filename.jpg" rendition="rendition_name" />

Provides the path to the image file specified, in the size specified by the rendition option if there are multiple renditions.

<w:assets:each tag="tagname">

Iterate through each of the asset files (typically images) that match the specified tag (if any).

<w:assets:each tag="var[w:kb:item:tag]">

Iterate through all of the assets tagged with the same tag as the current item. The "var[w:kb:item:tag]" syntax is a workaround needed because WebvantaScript cannot be nested. (This statement only works predictably with items that have only one tag.)

Menu

<w:menu>

Iterate through each of the top-level menu items, as set by the Page admin. Typically used to generate main navigation.

<w:if_submenu>

If the current menu item has a submenu, include the following code.

<w:submenu:each>

Iterate through each submenu of the current menu.

<w:if_ancestor_or_self>

Use instead of if_selected to add a class to highlight the curent page, if you want the highlight to show for any second-level page that has the corresponding page as its parent.

<w:if_selected>

Used within menu-generation code to highlight the current page. Include the following code if the current page's URL matches that of a particular menu item.

<w:unless_last_menu >

Use to wrap around divider between menu items, so you don't get a divider after the last one.

<w:label />

Provides the label for a menu item. Must be used in the context of a menu iterator.

Displaying Database Items

<w:fieldname format="options" />

Display the contents of a single field for the currently selected database item (as determined by the context).

<w:path url="/item_page" />

Provides the path to the item page for the current item, including item ID and name.

<w:escape_html>

Escapes all special characters in the following code, so HTML will be displayed rather than interpreted.

<w:kb:edit>

Marks the code section that is highlighted when hovering to edit a database item in-place.

<w:created_at format="format string" />

Displays the date and time at which a database item was created, formatted as you'd like. See article and examples for format string details.

<w:seo_keywords />

Displays the meta keywords of the database item.

<w:seo_description />

Displays the meta description of the database item.

<w:seo_title />

Displays the meta page title of the database item.

<w:modified_at format="format string" />

Displays the date and time at which a database item was last modified.

<w:published_at format="format string" />

Displays date at which a database item was published.

Fieldsets & Related Items

<w:get name="name" />

Display a field that is associated with the current item. Note that this is needed only for fields that are not part of the base item (such as fieldsets or related items).

<w:for_each in="item_name">

Iterates through each of the associated items in item_name. Use for fieldsets and related items.

Conditionals

<w:if_item type="item-type">

Include following code only if the currently selected item is of the indicated type.

<w:unless_xxxxxxx>

For every "if_xxxxxx" statement, there is a corresponding "unless_xxxxxx" statement. (Note that this is not "else"; you must state the condition, just as in the if statement.)

<w:if_url matches="regex">

Include following code only if the URL (not including the domain name) matches the specified regular expression.

<w:if_comments>

Include following code only if there are comments on the current item.

<w:if condition="name.blank?">

Displays the markup following this statement if the specified field has no contents.

<w:random>

Choose randomly from the supplied options (see example). Note that this is useful only un uncached pages.

<w:if_first>

Include following code if current page is the first in a set of subpages.

<w:if condition='fieldname=="text" '>

Displays the markup following this statement only if the contents of the specified field equals the specified text.

<w:if_self>

Include the following code if the current page context (typically within an iteration loop) matches the current displayed page.

<w:kb:item:if_iterator_preflight_size count="xx">

Includes the following code only if the number of items returned by the iterator would be greater than the count value.

<w:if condition="fieldname == 1">

Test whether a custom item's checkbox field is checked

<w:if_children>

Include the following code only if the current page has children.

<w:if_last>

Include following code only if current page is the last in a set of subpages.

<w:if_items category="category">

Include the following code only if there are items of the specified category and the current type. Must be used in an item type context.

Taxonomies

<w:taxonomy name="taxonomy_name:term_name">

Sets the current taxonomy term to the "term_name" term in the "taxonomy_name" taxonomy. Reference in an item iterator using taxonomy="current", or access the taxonomy's name and description with <w:name /> and <w:description />.

<w:taxonomy:each name="taxonomy-name">

Iterate through each of the terms in the taxonomy "taxonomy-name". See article for options.

Test if the current term for taxonomy context is the last one in the iteration.

<w:taxonomy:each:if_first>

Test if the current term for taxonomy context is the first one in the iteration.

<w:taxonomy:if_subterms>

Test to see if current term has any child terms associated with it. Add an attribute count="n" to test for at least n child terms.

<w:taxonomy:if_items type="type_name" count=n>

Test if the current term has more than n items assigned to it of the specified type.

<w:taxonomy:if_items type="type_name, type_name, type_name">

Test if the current term has any items assigned to it with any of the specified types. Add a minus sign in front of a type_name to exclude items of that type.

<w:taxonomy:if_items type="type_name">

Test if the current term has any items assigned to it of the specified type. If the type is not specified, checks for any type.

<w:taxonomy:if_current name='term_name'>

Tests if the current term matches the specified name.

<w:taxonomy:if_term name="term_name">

Tests if the current taxonomy term context matches the specified term name. Note: you can also provide the term ID instead of the name.

<w:taxonomy:if_term>

Tests if there is any taxonomy term context set.

<w:taxonomy:if_root>

Test if current term is a root term (i.e., it has no parent term)

<w:taxonomy:tree name='taxonomy_name' type='html'/>

Show a complete tree of all the terms in a taxonomy. Set type to "json" to get the tree in that format.

<w:description />

Displays the taxonomy term description (must be used in a taxonomy context)

<w:name />

Displays the name of the current taxonomy term (must be used in a taxonomy context)

<w:if_current>

Includes the following code only if the current taxonomy term matches the page's taxonomy term (for use only on category pages)

Snippets & Config Settings

<w:snippet name="snippet_name" />

Provides the contents of the specified snippet.

<w:snippet name="snippet_name">Variable</w:snippet>

With the two-part version of the snippet tag, you can pass any text as a variable to the snippet.

<w:yield />

Inserts content in a snippet from the code that invokes the snippet.

<w:data name="setting_name" />

Provides the value of the specified configuration setting. Useful in CSS and JS files as well as in templates and editable regions.

Comments

<w:comment_count />

Display the number of comments on the current item.

<w:kb:item:comments:each (options)>

Iterate through each of the comments on the current item. See examples for options and field names.

<w:if_comments>

Include following code only if there are comments on the current item.

Users

<w:account key="domain" />

Provides the domain name for the current account.

Variables

<w:var name="variable-name">value</w:var>

Sets the variable to the specified value.

<w:var name="variable-name" />

Returns the value of the variable "variable-name". Note: in WebvantaScript, use {{variable-name}} to access variables.

Misc

<w:random>

Choose randomly from the supplied options (see example). Note that this is useful only un uncached pages.

<w:resource:type />

Displays the cit name of the item. Use in a kb:item:each loop.

<w:comment>

Use to "comment out" WebvantaScript code. (note that commenting out with HTML comments does not work for WebvantaScript.