Branching Logic

A simple method of conditionally rendering content lies in LXP’s native support for a small set of branching logic tags. These allow you to either display or hide regions of markup by performing equivalence checks on variables or cookies. LXP’s basic branching logic tags include:

  • <if>

  • <ifnot>

  • <ifcookie>

  • <ifnotcookie>

  • <else>

  • <elseif>

  • <elseifnot>

The <if> and <ifnot> tags operate on LXP variables (or object variable values), whereas the <ifcookie> and <ifnotcookie> tags operate on stored cookies for the current domain. In other words, the logical functions of <if> and <ifcookie> are the same; only the sources for logical evaluation differ.

The <else> tag is more generalized, and implements subsequent, inverted logic evaluations on any of the previously mentioned tags. The <elseif> and <elseifnot> tags are actually just shortcut tags with the same result as nesting an <if> or <ifnot> tag within an <else> region.

The <if> and <ifnot> Tags

When used without any accompanying attributes, the <if> and <ifnot> tags perform no useful function. However, with meaningful attributes, these tags can be used to quickly and simply flag regions of mark-up for display under specific circumstances.

Using <if>

The <if> tag examines its defined attributes through equivalence comparisons to variables whose names match the attribute names. If the specified attribute’s value matches the variable’s value exactly, the region of mark-up between that <if> and its associated </if> closing tag will be processed ...

Get Practical PostgreSQL now with the O’Reilly learning platform.

O’Reilly members experience live online training, plus books, videos, and digital content from nearly 200 publishers.