Using STJ
StackState Self-hosted v4.5.x

Overview

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).
STJ is based on handlebars (handlebarsjs.com) and comes with a number of StackState functions.

Handlebars syntax

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:
1
[{
2
"_type": "Component",
3
"checks": [],
4
"streams": [],
5
"labels": [],
6
"name": "{{ name }}",
7
"description": "{{ description }}",
8
"type" : {{ componentTypeId }},
9
"layer": {{ layerId }},
10
"domain": {{ domainId }},
11
"environments": [{{ environmentId }}]
12
}]
Copied!

Conditionals: #if / else

Run some template code conditionally if a variable has a value.
Template
Data
Result
1
{{# if description }}
2
"description": "{{ description }}",
3
{{else}}
4
"description": "noop",
5
{{/ if }}
Copied!
1
[ description: "hello world" ]
Copied!
1
"description": "hello world"
Copied!

Looping: #each

Loop over an array or map of data.
Template
Data
Result
1
[
2
{{# each names }}
3
"hello {{this}}",
4
{{/ each }}
5
"bye y'all!"
6
]
Copied!
1
[ names: [ "stackstate", "handlebars" ]]
Copied!
1
[
2
"hello stackstate",
3
"hello handlebars",
4
"bye y'all!"
5
]
Copied!

StackState Functions

StackState adds a number of function to the handlebars syntax. You can use these to create complex JSON results.

Component and relation templates

Templates are used to create topology.

See also

Last modified 20d ago