Skip to content

03. Twig Tags

JoomlaBoat edited this page Apr 25, 2022 · 4 revisions

Twig for Template Designers

This document describes the syntax and semantics of the template engine and will be most useful as reference to those creating Twig templates. Synopsis

A template contains variables or expressions, which get replaced with values when the template is evaluated, and tags, which control the template's logic.

Below is a minimal template that illustrates a few basics:

<table>
	<thead>
		<tr>
			<th>{{ html.batch("checkbox") }}</th>
			<th>#</th>
			<th>{{ age.title }}</th>
			<th>{{ name.title }}</th>
			<th>{{ lastname.title }}</th>
			<th></th>
		</tr>
	</thead>
	<tbody>
		{% block record %}
		<tr>
			<td>{{ html.toolbar("checkbox") }}</td>
			<td><a href='{{ record.link(true) }}'>{{ record.id }}</a></td>
			<td>{{ age }}</td>
			<td>{{ name }}</td>
			<td>{{ lastname }}</td>
			<td>{{ html.toolbar("edit","delete") }}</td>
		</tr>
		{% endblock %}
	</tbody>
</table>

There are two kinds of delimiters: {% ... %} and {{ ... }}. The first one is used to execute statements such as if statements, the latter outputs the result of an expression.

More here: Twig Documentation