This page documents how FHIR uses the [Liquid language] for templating.

The liquid templating engine is used for the following purposes:

Broadly, FHIR applications that use Liquid templating:

Contents

Evaluation Context

Whenever a Liquid template is executed, there's a single object that is the focus that the template is occurring in.

In addition to the focus object, other variables may be provided as specified (where?)

Using Liquid Statements

The following liquid statements are used, with the functionality as documented

Statement

A statement consists of 2 pairs of braces with a FHIRPath statement:

 {{ expression }}

Comments

 Anything you put between {% comment %} and {% endcomment %} tags
 is turned into a comment.

Allows you to leave un-rendered code inside a Liquid template. Any text within the opening and closing comment blocks will not be output, and any Liquid code within will not be executed.

If

The if control tag is

 {% if expression %}
 {% else %}
 {% endif %}

Loop

Note: Loop is deprecated in favor of the For control flow tag

The loop control tag is

 {% loop var in expression %}
   {{ var.expression }}
 {% endloop %}

For

Note: For implementation is in progress as of 5/22/2020

The for control tag is

 {% for var in expression %}
   {{ var.expression }}
 {% endfor %}

Else

The else tag specifies a fallback for a for loop which has no elements

 {% for var in expression %}
   {{ var.expression }}
{% else %}
The collection is empty. {% endfor %}

Break

The break tag is used to break out of a loop

 {% for var in expression %}
   {{ var.expression }}
{% if expression %}
{% break %}
{% endif %}
{% endfor %}

Continue

The continue tag is used to continue to the next iteration of a loop

{% for var in expression %}
   {{ var.expression }}
{% if expression %}
{% continue %}
{% endif %}
{% endfor %}

Cycle

The cycle tag is used to cycle through a list of items within each iteration of a for loop

 {% for var in expression %}
   {{ var.expression }}
{% cycle "odd", "even" %}
{% endfor %}

Limit

The limit parameter is used in a for loop to limit the number of iterations

 {% for var in expression limit:2 %}
   {{ var.expression }}
{% endfor %}

Offset

The offset parameter is used in a for loop to skip a specified number of iterations

 {% for var in expression offset:2 %}
   {{ var.expression }}
{% endfor %}

Range

Liquid defines a way to iterate a range of numbers (for i in (3..5) but this is ambiguous with FHIRPath grammar and not supported.

Reversed

The reversed tag reversed the order of the elements in the loop

 {% for var in expression reversed %}
   {{ var.expression }}
{% endfor %}

Include

The include control tag works like this:

 {%include filename parameters %}

e.g. the following include:

 {%loop name in Patient.name%}{%include humanname.html name=name%}{%endloop%}

would lead to a statement like this in the included file:

 {{include.name.family}}

todo