Twig basics

Estimated reading: 1 minute

Twig delimiters

Whenever you create a Twig template you can use three kinds of delimiters:

1. Render delimiter

{{ foo }}

this delimiter is used when you want to render something to the browser directly, or return something (more on that later).

It’s comparable to the PHP ‘echo’ construct.

2. Execute statements

{% for item in posts %}
{% endfor %}

This delimiter {%%} does not render anything, but is used to execute statements such as for-loops, include, import, set values and control inheritance.

3. Comments

{# this is a comment #}

Comments are an important part of the template. It allows you to write something about the template to explain something, or temporarily disable a part of the logic.

Share this Doc

Twig basics

Or copy link

CONTENTS