Skip to content

Fortified IDDocs

Advanced expansion

Advanced expansion reference and configuration shared across Fortified ID products.

Expansion expressions can not contain logic (if/else/etc), but it is possible to iterate lists and include/exclude content based on specific conditions using sections.

Sections enable conditional rendering and iteration using mustache syntax. A section starts with {{#name}} and ends with {{/name}}.

A section MUST:

  • start with tag {{#<name>}}
  • end with tag {{/<name>}}
  • reference a property by (path and) name

A section MAY:

  • contain expansion expressions (${...})
  • static text

Sections behave different depending on the type of the referenced property:

  • If the property doesn't exist, has no value or is false nothing will be rendered
  • If the property is a list (multi-value) the content of the section will be rendered for each element in the list
  • Otherwise section content will be rendered once

Within a section, ${.} references the current value or list element and is implicit when referencing properties on the current element (${name} expands to property name on the current element).

Standard property paths are also available and search the current context first, then top-level scopes.

{{#items}}${.}{{/items}}
{{#user}}${name} (${id}){{/user}}
{{#response.user}}${name}{{/response.user}}

An inverted section ({{^name}}) renders when the value is absent, false, or an empty list — the opposite of a regular section.

{{^errors}}No errors.{{/errors}}
{{^items}}The list is empty.{{/items}}

Inside a list section, mustache provides some built-in variables:

VariableMeaning
{{@last}}True for the last element in the list
{{@first}}True for the first element in the list
{{@index}}Zero-based index of the current element

These are typically used with inverted sections to control separators:

{{#items}}${.}{{^@last}}, {{/@last}}{{/items}} → a, b, c

By default, {{value}} escapes HTML special characters. Use triple braces to output raw values:

{{{value}}}

Both syntaxes can be used in the same value. As soon as mustache syntax ({{) is detected, the entire value is processed as a mustache template — including all ${...} expressions.

User: ${user.name} — active: {{user.active}}

Note: bracket notation (${list[0]}, ${obj['key']}) is not supported in mustache context. Use dot notation instead:

Given the following list of strings:

"list" : ["elem01", "elem02", "elem03"]

this expression:

{{#list}}${.},{{/list}}

will render (note the trailing comma):

elem01,elem02,elem03,

To remove the trailing comma, we can embed an inverted section using the @last property on the current list item (only rendered when element is not "last" in list):

{{#list}}${.}{{^@last}}, {{/@last}}{{/list}}

This will render:

elem01, elem02, elem03

Given the following object:

"user": {
"id": "user00",
"name": "First user"
}

this expression:

{{#user}}User: ${name} (id: ${id}){{/user}}

will render:

User: First user (id: user00)