Skip to content

Generation variables

A template doesn’t know your project. Generation variables are the bridge: the template declares the variables it needs, and you fill in their value in Restorm. At generation time, each value is evaluated then injected into the template context.

The generation-variables editor: the variables declared by a template and their value in Handlebars, by scope

Each variable is declared by the template (in its restorm-template.json) with a name, a scope, a type, a default value and an optional description. On the Restorm side, you fill in its value as a Handlebars expression — evaluated for each entity concerned, then converted to the declared type.

The possible types are string, boolean, number and enum (with its list of options).

A Discover the variables used by this template action analyzes the template and flags the variables used but not declared, to avoid oversights.

The scope decides at which level the variable is evaluated and where it lands in the template context:

ScopeEvaluatedAvailable in the template
Projectoncectx.design.vars.<name>
Modelper modelctx.models[].vars.<name>
Propertyper propertyctx.models[].properties[].vars.<name>
Routeper routectx.groups[].routes[].vars.<name>

For each template, you define general values by scope (the “general variables”, which apply for example to all models). You can then override a variable for a given model, property or route, from the entity’s Code generation tab. An empty value means “inherit”: the first non-empty value wins, and any unresolved value surfaces as an error — never silently.