Code Islands

Jtwig is a Twig port to Java, however, it does not support all Twig features and also includes functionality Twig does not offer. Syntax wise, they do also differ. This difference is due to Java environment specifics. To allow the engine to take full advantage of its mother language, some fundamental changes were introduced. Within this section one will detail all possible code islands.


As a template language, Jtwig allows one to have formatting or control flow logic around content. In order to do so, Jtwig uses the so called Code Islands. This is similar to many template languages and identical to Twig's syntax.

{% code %}

Jtwig code islands begin with {% and ends with %}, just as simple as that.

Whitespace Control

Tied up with the code island syntax is another syntactical enabled feature, 100% compatible with Twig, the white space control functionality. This allows one to remove white spaces before or after a code island. In order to accomplish that, append/prepend the symbol - to the beginning/ending of the Jtwig code island. Let's take for example:

{% block test -%} text {%- endblock %}

Such code will produce text without white spaces.


In Jtwig there are only multiline comments.

{# This is the content of the comment.
And it can be a multi-line content.  #}

Note that comments also support the white space control feature, using the same approach as per code islands.

{#- Comment... -#}


In Jtwig there is only one way to write the value of an expression (the definition of expression will be detailed afterwards) to the output. That is accomplished with the print operation as shown below.

{{ expression }}

Again, output constructs also support white space control feature in the same way as code islands.

{{- expression -}}