Miscellaneous
#log
Logs values to the tracer. It does not render output.
Block form:
Log levels are NOT supported.
either
Returns the first non-falsy value among context and params
Usage:
If the preferredLabel is true value, it will be return.
If the preferredLabel is falsy value, it will return fallbackLabel.
If the fallbackLabelis falsy, it will return "N/A"
filter
Filter the context object by one or more pairs of field and field values and return an array of the resulting item. Optionally, matching can be done using XPath, which allows for more complex conditions.
0: field name: (string) name of a JSON property
1: value: (variant) to match against the content of the field
2, 3, etc.: further fieldName-value pairs matching in an OR matter
generateId
Create a document local unique ID for a data context.
Usage:
Typically, used for creating unique IDs for text anchors.
See the similar XPath 1.0 function.
sort
For data context:
{"people": [
{"firstname": "Susan", "lastname": "Doe", "age": 21, "country": "AT"},
{"firstname": "John", "lastname": "Doe", "age": 23, "country": "DE"}
]}
Result:
<ul>
<li>John Doe</li>
<li>Susan Doe</li>
</ul>
Sort can be embedded in other sort.
when
Ternary helper with optional regex guard when context is truthy
Usage:
If apply below input:
{
"active": true
}
The result will be Enabled.
If "active": false, the result will be Disabled
This helper comes with regex option:
Example:
If the input data is:
{
"email": "john@example.com"
}
Result will be VALID EMAIL
If "email": "abc", result will be INVALID EMAIL.
xpath
This xpath helper evaluates a XPath expression against the current context.
This allows using complex XPath expressions in the template, e.g., to 'look up' or 'look aside' in the data.
The JXPath engine is used for evaluation, both for XML and JSON (https://commons.apache.org/proper/commons-jxpath/).
Usage:
With this input data:
{
"product": {
"name": "Laptop",
"price": 1200,
"category": {
"name": "Electronics"
},
"variants": [
"a",
"b",
"c"
]
}
}
Template:
Result:
<div>
Name: Laptop</p>
Category: Electronics</p>
Number of Variants: 3</p>
</div>