Using the setVar
and getVar
helpers you can create template-scoped (or local) variables to save some intermediate data in your templates and avoid repeating the same logic multiple times.
Unlike global variables which are shared between all routes of an environment, local variables are scoped to the template they are used in. Their values are regenerated each time the template is re-evaluated.
⚠️These variables are not shared between routes or responses.
Local variables are available everywhere templating helpers are supported.
To set and access local variables, two templating helpers are available.
To set a variable, use the setVar
helper. This helper takes two arguments: the variable name and its value. You can dynamically set the parameters using other helpers.
Some examples:
Copy
To get a global variable, use the getVar
helper or refer to the variable with its name prefixed with an @
. The helper takes two arguments: the variable name and an optional path. You can dynamically set the parameters using other helpers and use the fetched data in other helpers.
Some examples:
Copy# Set a variable # Get a variable