include construct

The simpliest modular construct in Jtwig is the include construct. By using this construct one can include another template.

{% include 'template.twig' ignore missing with {} only %}

The previous example shows all include possible arguments. In this section one will describe all arguments in detail.

Path (mandatory)

In it's simple form include only requires one argument, the template path. This is an expression which will be evaluated and used as the path for the Jtwig template to include.

{% include templatePath %}

The way Jtwig resolves the given path to a specific resource is configurable and will be detailed later.

ignore missing (optional)

If Jtwig resource resolution is not able to find the given resource, include will, by default, throw an error. When the argument ignore missing is set, Jtwig will ignore missing resources and proceed with the rendering.

{% include templatePath ignore missing %}

with <expression> (optional)

The with argument adds the capability to provide model variables to the included template. The expression is expected to be evaluated as a map.

{% include templatePath with { key: 'value' } %}

only (optional)

The only argument tells the engine to isolate the included template from the parent context. That way variables currently defined in the context won't be visible in the included template.