Category Syntax

The value of a category-backed property is a set of zero or more individual category values.

Property Description Example
id A unique system ID for the category, suitable for passing as a request parameter. ny
name The system-recognized keyword for the category. new_york
label The descriptive label of the category, appropriate for displaying to website visitors. New York
path The category path colors/primary/red

These values can be displayed by using the t:list iterator with an ID attribute that corresponds to the property name. For example:

<t:list id="category_property_name">
<t:value id="label">Category Name Goes Here</t:value>
</t:list>

It often makes sense to use <t:if> tests for index and length when displaying categories. For example:

<t:if test="category_property_name.length > 0">
<t:list id="category_property_name">
<t:value id="label">Category Name</t:value>
<t:if test="index < length"><br /> </t:if>
</t:list>
</t:if>

Would render the following HTML for 3 related categories:

  • Category A
  • Category B
  • Category C

If you want to quickly print out any categories selected for a category-backed property field, you can simply print ${category_property_name}. The output will look like this:

Category A, Category B, Category C

It is also possible to render a set of categories outside the context of an item. The first step is to define a categories data source:

<t:data name="colors" class="categories" parent="/color" />

This defines a data source named colors that refers to the category named color that lives under the top category.

Once the data source is defined, it can be accessed using the standard <t:list> syntax:

<t:list id="colors">
<div>${label}</div>
</t:list>

Here is an example of rendering an HTML form select list based on a set of categories.

<t:data name="colors" class="categories" parent="/color" />
<form>
Select a color:
<select name="color">
<t:list id="colors">
<option value="${name}">${label}
</t:list>
</select>
</form>