Flexible Twig Templates in Craft 3
The last of the three handler templates is one for all Matrix fields in the site.
The matrix
template is special handler. Unlike the other two we already discussed, it doesn’t handle general layouts. Instead, it is the generic template for all Matrix fields on the site.
The code in the Matrix template is a simple for
-loop that loops over each block in the Matrix field and includes a template to format and render the content that that Matrix field returns.
{% for block in matrix %}
{% include ["matrix/" ~ block.type, "matrix/default"] %}
{% endfor %}
Like we did in earlier templates, we’re leaning on Twig’s include
statement and feeding it a list of template possibilities.
Flexible Twig Templates in Craft 3 is made up of the following videos: