Bracket Expression
[key]
Evaluates key
and looks up the result in the scope.
{{[key]}}
Parameters
- key
{Literal Expression|KeyLookup Expression|Call Expression|Helper Expression}
:A Literal, KeyLookup, Call, or Helper expression to evaluate and look up the result in the scope.
CALL_EXPRESSION[key]
Evaluates key
and looks up the result in the return value of CALL_EXPRESSION
.
{{method()[key]}}
Parameters
- CALL_EXPRESSION
{Call Expression|Helper Expression|KeyLookup Expression}
:A Call, Helper, or KeyLookup expression that may or may not return a value.
- key
{Literal Expression|KeyLookup Expression|Call Expression|Helper Expression}
:A Literal, KeyLookup, Call, or Helper expression to evaluate and look up the result in the result of
CALL_EXPRESSION
.
Use
A bracket expression can be used to look up a dynamic property in the scope. This looks like:
<!-- Template -->
<h1>{{[key]}}</h1>
{
key: "name",
name: "Kevin"
}
<!-- Result -->
<h1>Kevin</h1>
This can be useful for looking up values using keys containing non-alphabetic characters:
<!-- Template -->
<h1>{{["person:"]}}</h1>
{
"person:name": "Kevin"
}
<!-- Result -->
<h1>Kevin</h1>
Bracket expressions can also be used to look up a value in the result of another expression:
<!-- Template -->
{{getPerson()[key]}}
{
key: "name",
getPerson: function() {
return {
name: "Kevin"
};
}
}
<!-- Result -->
<h1>Kevin</h1>