let
· Context variables
Declare variables for the current context and its children, which can be used in templating expressions to create dynamic values.
- _: Say hi
log: ${greeting}
let:
greeting: Bonjour, mes amis !
CAUTION
The esquie
and __
identifiers are reserved and cannot be used as a variable name. Attempting to do so will throw an error at runtime.
Variables inheritance
Esquie variables behave similarly to JavaScript scopes, where child contexts inherit values from parent contexts, unless shadowed.
let:
b: foo
c: bar
# d: # ReferenceError
tasks:
- _: Explaining variables inheritance
let:
a: foo # defined
b: qux # overridden
# c: bar # inherited
- _: --------------------------------
let:
# a: # ReferenceError
# b: foo # inherited
# c: bar # inherited
d: boo # defined
About templating order
Since records are templatized depth-first and in declaration order (as explained in the templating rules), you may use variables defined earlier in the same let
block.
let:
a: foo
tasks:
- _: Showcasing templating order
let:
a: ${a}bar # "foobar"
b:
a: ${a}${b} # "foobar"
b: ${b.a} # "foobar"
CAUTION
for
and let
properties (in this order) are exceptions to the general templating order rule, as they are templatized before any other property in the same context.
- log: ${greeting} # "Bonjour, mes amis !"
let:
greeting: Bonjour, mes amis !
WARNING
While the let
property can itself be templatized, resulting value will not be further templatized (as explained in the templating rules.)
- log: ${foo.bar} # "${true}"
let:
foo: "${ { bar: '${true}' } } "