Flexible Twig Templates in Craft 3
The item handler templates let us display individual entries in a listing view.
The Listing Item Template, which we’ve named item.twig
in the implementation of the sample site Downlink, handles the content layouts for the listing pages, like category pages or entries by tag. This includes the homepage, where we have a listing of the different content from the site (two types of Blog content and Podcast episodes).
The reason we have the Listing Item Template separate from the Entry Template is so we can display our entry content in a different way on listing pages. Sometimes, for example, listing pages, like a homepage or category page, have truncated entry content or excerpts with a link to read more. If we used the full Entry template to handle this then we’d have to make that template handle more than one scenario, which increases the complexity of our templates.
Like the Entry template we just discussed, the Listing Item Template uses an include
statement and a list of dynamically-generated template names.
{% include ["item/" ~ entry.section.handle ~ "/" ~ entry.type,
"item/" ~ entry.section.handle ~ "/default", "item/default"] %}
Flexible Twig Templates in Craft 3 is made up of the following videos: