Escaping Templatized Values & Inputs
In Unmeshed, we use a templating language that allows dynamic evaluation of inputs, variables, and expressions using double curly braces {{ ... }}
syntax.
Templating Syntax
The standard syntax for referencing dynamic values in Unmeshed is:
{{ context.input.id }}
When Unmeshed processes this, it replaces the template with the actual value of context.input.id
.
Why Escaping Is Needed
In some cases, you may want to use {{ context.input.id }}
literally as an input or value, without it being evaluated by the templating engine. If you use the standard syntax, Unmeshed will always try to resolve it, which might not be what you want.
How to Escape a Template
To prevent Unmeshed from evaluating a template expression, prefix the template path with __escape
. The format is:
{{ __escape.context.input.id }}
When Unmeshed evaluator sees this, it will output the string {{ context.input.id }}
as plain text, without attempting to resolve it.
Examples
Without Escaping (Evaluated):
Input: {{ context.input.id }}
Output: 12345 // (Assuming context.input.id = 12345)
With Escaping (Not Evaluated):
Input: {{ __escape.context.input.id }}
Output: {{ context.input.id }}
When to Use Escaping
- When you want to pass the template string to another system or process for later evaluation.
- When you need to prevent accidental evaluation of template-like strings.
Summary
- Use
{{ context.input.id }}
to evaluate and insert dynamic values. - Use
{{ __escape.context.input.id }}
to escape and output the template as plain text.
This escaping mechanism ensures you have full control over when and how template expressions are evaluated in Unmeshed.