TemplateDX doesn’t have variable declarations. At render time, the caller passes a props object to transform(); your template reads those values with {props.*} expressions. Tag plugins can introduce additional scoped variables (for example, <ForEach> gives you the loop iterand).
Accessing variables
Dot notation
Read nested properties with dot notation, same as JavaScript:
Bracket syntax
Bracket syntax works for dynamic or hyphenated keys:
Undefined-variable behavior
Nothing in this path throws, so a typo degrades silently. The two cases degrade differently:
- Missing nested properties (anything after a
. or [...]) render as an empty string:
- Bare unknown identifiers (no
props. prefix) resolve to undefined and render the literal string undefined into your output:
A typo in a <ForEach> iterand is the common way this corrupts prompts: writing {itme} instead of {item} injects the string undefined into every iteration, with no error or warning. Prefer the props. prefix wherever possible, since unknown nested keys degrade to an empty string instead of the string undefined.
Only variables provided by the caller’s props, introduced by a tag plugin’s scope (such as the <ForEach> iterand), or registered filters (see Filters) are accessible. JavaScript globals aren’t.
Examples
Defined variable
Nested properties
Bracket syntax for dynamic properties
Undefined nested property
(renders empty string)
Undefined bare identifier
(renders the literal string undefined; the caller passed props.username, but the expression forgot the prefix)
Next steps
Variables are the simplest expressions. See Expressions for operators, literals, and filter calls.