This documentation and the Cisco Observability Platform functionalities it describes are subject to change. Data saved on the platform may disappear and APIs may change without notice.
Parameterized Templates
When templates are used as building blocks, the topology context of the parent element is passed to the child template. A template can also receive further configuration from the parent element if you define configuration parameters (props
). The values that you specify for props
in the parent element are then used to modify the building block of the parameterized template. The parameterized
template itself contains this modification logic in the form of a JSONata expression with is located under the key preprocess
.
This expression receives the template element
of the parameterized template as input as well as the props
. The values of the props
declared in the parameterized template are default values, which are used if not specified by the parent template. The result of the expression then replaces the template element before it is used in the rendering process.
Example:
{
"name": "mysolution:exampleParameterizedTemplate",
"props": {
"customContent": "element at position 1"
},
"preprocess": "$ ~> |elements[1].element|{ \"content\": $props.customContent }|",
"element": {
"instanceOf": "elements",
"elements": [
{
"instanceOf": "text",
"content": "element at position 0"
},
{
"instanceOf": "html",
"element": {
"instanceOf": "text"
...
}
}
]
}
}
Preprocess receives the following bindings:
$
: The rootelement
$props
: The result of merging the declaredprops
with the passedprops
{ ...declaredProps, ...passedProps }
Using a Parameterized Template as a Building Block
The parent template specifies the values for the props
of a parameterized template in the same way as it does for atomic building blocks:
"element": {
"instanceof": "mysolution:exampleParameterizedTemplate",
"customContent": ""
}