Difference between revisions of "FHIR Liquid Profile"
(→Loop) |
|||
(3 intermediate revisions by one other user not shown) | |||
Line 1: | Line 1: | ||
− | This page documents how FHIR uses the Liquid language for templating. | + | Content on this page has been migrated to Confluence here: https://confluence.hl7.org/display/FHIR/FHIR+Liquid+Profile |
+ | |||
+ | |||
+ | This page documents how FHIR uses the [[https://shopify.github.io/liquid/ Liquid language]] for templating. | ||
The liquid templating engine is used for the following purposes: | The liquid templating engine is used for the following purposes: | ||
Line 8: | Line 11: | ||
* Use a small subset of the liquid language (the syntax, and none of the functions) | * Use a small subset of the liquid language (the syntax, and none of the functions) | ||
* Replace liquid expressions with FHIRPath expressions | * Replace liquid expressions with FHIRPath expressions | ||
+ | |||
+ | Important note about this page: wiki treats the template tags that start with 2 { and finish with 2 } as a special case and doesn't render them properly. So we close the examples on this page with ]} but that actually means }} | ||
= Evaluation Context = | = Evaluation Context = | ||
Line 56: | Line 61: | ||
{% loop var in expression %} | {% loop var in expression %} | ||
− | {{ var.expression | + | {{ var.expression ]} |
{% endloop %} | {% endloop %} | ||
Line 80: | Line 85: | ||
would lead to a statement like this in the included file: | would lead to a statement like this in the included file: | ||
− | {{include.name.family | + | {{include.name.family]} |
== todo == | == todo == |
Latest revision as of 18:50, 3 January 2020
Content on this page has been migrated to Confluence here: https://confluence.hl7.org/display/FHIR/FHIR+Liquid+Profile
This page documents how FHIR uses the [Liquid language] for templating.
The liquid templating engine is used for the following purposes:
- Building narratives for resources
- Building resources from external data sources (V2, CDA, etc)
Broadly, FHIR applications that use Liquid templating:
- Use a small subset of the liquid language (the syntax, and none of the functions)
- Replace liquid expressions with FHIRPath expressions
Important note about this page: wiki treats the template tags that start with 2 { and finish with 2 } as a special case and doesn't render them properly. So we close the examples on this page with ]} but that actually means }}
Contents
Evaluation Context
Whenever a Liquid template is executed, there's a single object that is the focus that the template is occurring in.
- When generating a resource, the resource itself is the focus.
- In other contexts, the focus object must be explicitly specified.
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 ]}
- Whitespace may be present before or after the expression statement, and is not significant.
- The expression is executed in the context of the focus object (but may reference other variables)
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 %}
- The expression is executed in the context of the focus object (but may reference other variables)
- Whitespace may be present in the tags, and is not significant.
- the else tag is optional
- {% elseif expression %} is also allowed
Loop
The loop control tag is
{% loop var in expression %} {{ var.expression ]} {% endloop %}
- The loop will run once for each object returned by the expression
- The loop variable is available to expressions using the named parameter
- Whitespace may be present in the tags, and is not significant.
Include
The include control tag works like this:
{%include filename parameters %}
- the filename resolution is outside this spec
- Whitespace may be present in the tags, and is not significant.
- the parameters is a list of name=expression pairs, separated by whitespace
- the parameters are available in the included file using the variable "include"
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
- What other liquid control things should be supported?
- date syntax wrangling