Comment on page
Using STJ
StackState SaaS
StackState's graph is entirely configured using JSON. To make it easy to work with large quantities of (often repetitive) JSON, StackState comes with the StackState Template JSON format (STJ).
StackState template files use handlebars. Content that is placed between double curly brackets
{{ some content }}
is included in the output. The example below shows handlebars used in a component template:[{
"_type": "Component",
"checks": [],
"streams": [],
"labels": [],
"name": "{{ name }}",
"description": "{{ description }}",
"type" : {{ componentTypeId }},
"layer": {{ layerId }},
"domain": {{ domainId }},
"environments": [{{ environmentId }}]
}]
Run some template code conditionally if a variable has a value.
Template
Data
Result
{{# if description }}
"description": "{{ description }}",
{{else}}
"description": "noop",
{{/ if }}
[ description: "hello world" ]
"description": "hello world"
Loop over an array or map of data.
Template
Data
Result
[
{{# each names }}
"hello {{this}}",
{{/ each }}
"bye y'all!"
]
[ names: [ "stackstate", "handlebars" ]]
[
"hello stackstate",
"hello handlebars",
"bye y'all!"
]
StackState adds a number of function to the handlebars syntax. You can use these to create complex JSON results.
Templates are used to create topology.
Last modified 1yr ago