Commands

Command constructs allows one to run specific commands against Jtwig. An important aspect common to all commands is that they never produce content, they only produce side effects.

set command

The set command allows to specify an assignment operation inside a Jtwig template, it will assign to the result of an expression to the specified variable.

{% set var = 2 + 3 %}

In the previous example one assigned the result of evaluating the expression 2 + 3 to the variable var. Note again that the output of the previous example will be empty because, as mentioned before, set as a command, does not produce content, it just affects the context defining, or redefining a variable.

do command

The do command just evaluates a given expression.

{% do something.run() %}

There is not a lot to say about this construct, it might be usefull to trigger behaviour from the template by running a Java method for example.

flush command

A common operation over streams is the flush operation. As a template engine Jtwig is very much associated with output buffers, which can be explicitly flushed. This forces the buffer to be flushed, for example, in a web application it will force the data to be sent over the wire.

{% flush %}