Twig
Use the Twig templating language to format and transform CMS content.
The four building blocks
Where Twig runs in Elements
@raw()
{% if item.featured %}
<span class="badge">Featured</span>
{% endif %}
@endrawControl flow
Conditionals
Loops
The most useful filters in CMS context
date — format a date
date — format a datedefault — fall back when a value is missing
default — fall back when a value is missinglength — count items in an array or characters in a string
length — count items in an array or characters in a stringupper, lower, title, capitalize — change case
upper, lower, title, capitalize — change casestriptags — strip HTML
striptags — strip HTMLslice — take part of an array or string
slice — take part of an array or stringsplit and join — break apart and reassemble
split and join — break apart and reassembleescape (alias e) — make a string safe for output
escape (alias e) — make a string safe for outputChaining: a clean text excerpt
Variable assignment
Working with arrays
Common pitfalls
Useful resources
Last updated
Was this helpful?

