Flexible Twig Templates in Craft 3
The handler templates are what kick off the requests to the other supporting templates in the stack.
Handler templates are site-wide templates that handle all template behavior for a layout. Handler templates don’t typically do much more than handle the initial template request and then pass the work off to another layer of templates for the actual content rendering.
Similar to the _layout
template we use for the wrapper for our site, the handler templates are generic enough to be reused over and over again by rendered pages that have different content.
The handler templates are mostly content agnostic (just like the site’s _layout
template). They are set up in a way that allow them to handle different types of content from different Sections in Craft, regardless of Entry Type or the fields used.
The templates in our Downlink sample site that are handler template are:
entry.twig
— This template handles all of the requests for individual entry views of all sections of the site (except the Homepage Single section).item.twig
— This template handles all display of content on a listing page, regardless of which section is being displayed. We use this template on the homepage to display the latest entries.matrix.twig
This template handles all display of Matrix fields across the site. In our sample site we only have one Matrix field for the body
field in the Default Entry Type. However, if and when we have another Matrix field this handler template will be the first touch point of the layout process. Like the other two handler templates, matrix.twig
only handles the request to display a Matrix field, and then quickly hands that off to the appropriate field.Flexible Twig Templates in Craft 3 is made up of the following videos: