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.

Note:

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

Syntax

{if [!]NAME/}
TRUE_TEMPLATE_TEXT
{elseif [!]NAME2/}
ELSE_TRUE_TEMPLATE_TEXT
{else/}
FALSE_TEMPLATE_TEXT
{endif/}

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.

Example

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

Syntax

{case NAME/}
{when STRING1/}
TEMPLATE_TEXT1
{when STRING2/}
TEMPLATE_TEXT2
{otherwise/}
TEMPLATE_TEXT
{endcase/}

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.

Example

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.)
{when PRESIDENT/}
--
{otherwise/}
&SAL.
{endcase/}

3.10.3 Loop Directives

Syntax

{loop ["SEP"] NAME/}
TEMPLATE_TEXT
{endloop/}

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.

Example

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>
{endloop/}</ul>