Twig Syntax and Features
Understanding the Basics of Twig
1.
{{ ... }}
: This notation is used to display the content of variables.2.
{% ... %}
: This structure is employed to execute logic-based operations such as conditions and loops.Essential Twig Tags
extends
block
include
for
if
, elseif
, else
set
Extending Templates with extends
and block
extends
and block
tags within a Zid theme:
content
block in home.twig
will replace the corresponding content
block within layout.twig
. This pattern of inheritance ensures that you can maintain consistent design elements across different pages while customizing content as needed.zidapi_script
within your templates to enhance functionality or track analytics.layout.twig
, and how it is structured:
title
, content
, and footer
.Including Sub-templates with include
include
tag allows you to incorporate other templates into the current one, similar to a 'copy-paste' action:
Conditional Logic with if
, elseif
, else
and endif
if
statement allows you to conditionally display content. It can be combined with elseif
and else
for more complex conditions:
Variable Assignment with set
set
tag:
Twig Filters
escape
: Ensures the output is safe to render by escaping HTML characters.length
: Returns the number of items in a sequence or characters in a string.raw
: Outputs raw, unescaped data.Twig Functions
range
: Generates a sequence of numbers.include
: Incorporates other templates.Modified at 2024-07-28 14:52:55