3.10 Using Template Directives

Use template directives to control how attributes that support substitution strings are processed.

Template directives are only supported by specific attributes of the cards, interactive grid regions, and email templates. These directives are processed as part of client side substitutions. To determine if an attribute supports template directives, Page Designer Help includes the text "Supports Template Directives." See apex.util.applyTemplate in Oracle APEX JavaScript API Reference for more details on directive syntax.


Syntax descriptions text in square brackets is optional. You do not actually type the square brackets. Upper case text represents something as described in the description.

3.10.1 If Condition Directives


{if [!]NAME/}
{elseif [!]NAME2/}

Use the if directive to conditionally show text based on if an item or column has a value. The NAME is an item or column name. If the value of the column or item is true then the following text is output. The value is false if it is an empty string or ‘F’, ‘N’, or ‘0’. Any value that is not false is true. If the NAME is proceeded by exclamation point (!) then the following text is output if the value is false rather than true.

There can be zero or more elseif directives. The else directive is optional. The text after the first if or elseif directive that is true is output. If no if or elseif is true then the text after the else directive, if any, is output.


A cards report contains a column named DESCRIPTION. The following HTML Expression attribute will display the description if it is not null (empty string) and “No description.” otherwise.

{if DESCRIPTION/}&DESCRIPTION.{else/}No description.{endif/}

3.10.2 Case Condition Directives


{case NAME/}
{when STRING1/}
{when STRING2/}

Use the case directive to show text based on the value of an item or column. The NAME is an item or column name. The value is compared with the strings after each when directive and if they are equal then the following text is output. If no when directive matches then the text after the otherwise directive, if there is one, is output. The value and each string is trimmed of leading and trailing spaces before comparison. The comparison is case sensitive.


This example using the sample EMP table displays the compensation differently depending on the JOB. For sales people it shows both the salary and commission. For the president it shows “--” rather than salary and for all other jobs it shows just the salary.

{case JOB/}
{when SALESMAN/}
&SAL. (&COMM.)

3.10.3 Loop Directives


{loop ["SEP"] NAME/}

Use the loop directive to repeat text once for each item in a multi-value (character delimited) item or column value. The NAME is an item or column name that has multiple values separated by the character given by SEP. The default separator is ":". If SEP is more than one character it is treated as a regular expression.

The template text within the loop can use these substitution symbols:

  • APEX$ITEM - This is the value of the current item in the list.

  • APEX$I - This is 1 based index of the current item in the list.


The following example takes a column called TAGS that contains a comma (,) separated list of tags such as "apples,cherries,pears" and turns it into an HTML list that can be nicely styled with CSS.

<ul class="tags">{loop "," TAGS/}
  <li class="tag-item">&APEX$ITEM.</li>