ARCOS 7 Help

Template Expressions

Very often in templates, you want different HTML to be output under different circumstances. You can use template logic (conditional statements) in your code to do this. The simplest example would be:

<tmpl_if expression>
Code block
</tmpl_if>

The expression in the code above is a variable or statement that can be evaluated as true or false. The simplest example (which wouldn't be very useful) is:

<tmpl_if true>
Code block
</tmpl_if>

When a story that uses this template is published, the code block would always be inserted (because "true" is always true, which is why this example is not very useful).

A more interesting example would be where the expression is a variable or a condition that may not always be true.

An example where the expression is a variable is:

<tmpl_if is_form>
Code block
</tmpl_if>

When a story that uses this template is published, the code block above would be inserted only if the story is a form.

An example where the expression is a statement is:

<tmpl_if expr="section eq 'about'">
Code block
</tmpl_if>

When a story that uses this template is published, the code block above would be inserted only if the story is in the "about" category—or in other words, if its URL begins yoursite.org/about/

You can make complex expressions by combining one or more conditions as in the following examples:

<tmpl_if expr="(section eq 'about') && (subsection eq 'mission')">
Code block
</tmpl_if>

The && indicates and. When a story that uses this template is published, the code block above would be inserted only if the story is in the "about" category and in the "mission" subcategory—or in other words, if its URL begins yoursite.org/about/mission/

<tmpl_if expr="(section eq 'about') || (section eq 'news')">
Code block
</tmpl_if>

The || indicates or. When a story that uses this template is published, the code block above would be inserted only if the story is in the "about" category or the "news" category—or in other words, if its URL begins yoursite.org/about/ or yoursite.org/news/

You can include two, three, four, or as many conditions as you would like in an expression using the && (and) and || (or) operators. You can also combine variable and statements in a single expression.

<tmpl_if expr="is_form && ((section eq 'about') || (section eq 'news'))">
Code block
</tmpl_if>

When a story that uses this template is published, the code block above would be inserted only if the story is a form in the "about" or "news" categories.

More About Templating