- 14 Oct 2024
- 1 Minute to read
- Print
Expression Attributes
- Updated on 14 Oct 2024
- 1 Minute to read
- Print
Expression Attributes allow the setting of state (active: true/false), based on the state of payload/data of one or more other Attributes. This can easily be added to a “24/4 Template Layer Template“ in code, but the logic can in a lot of situations instead be done by the Player itself. For example:
We have a camera-sensor measuring the number of cars in a traffic intersection:
{
"name": "dyn.traffic",
"data": "15"
}
This is updated by a template, a Player Plugin or some other mechanism. To trigger on this, we can add some Expression Attributes that can be used as Conditionals in the CMS:
{
"name": "expr.lightTraffic",
"data": "{dyn.traffic}.VALUE < 10"
}
{
"name": "expr.mediumTraffic",
"data": "{dyn.traffic}.VALUE >= 10 && {dyn.traffic}.VALUE < 20"
}
{
"name": "expr.heavyTraffic",
"data": "{dyn.traffic}.VALUE >= 20"
}
These will then change the active-state dynamically, based on the “dyn.traffic” data-value.
The data-field frequently contains an object serialized as JSON and this is supported in the syntax.
The expression is JS-eval()’ed after massaging of the string, so any JS-operators are valid.
“{dyn.ExampleAttr}” - boolean. The active state of “dyn.exampleAttr“.
“{dyn.ExampleAttr}.VALUE“ - string. The unparsed data-value.
“{dyn.ExampleAttr}.myValue“ - The type and value of JSON.parse(attr.data).myValue.
“expr.mediumTraffic“ from the example above can therefore be defined as:
{
"name": "expr.mediumTraffic",
"data": "!{expr.lightTraffic} && !{expr.heavyTraffic}"
}