I’m starting a new project and thought i’d try twig.
I’ve been using stash and one of the features i liked was setting vars in one template and accessing them in another.
eg. my index templates (e.g. ‘about/index’) would just have 2 embeds {embed="_data/_main" url_title="{last_segment}"}
and {embed="_templates/_view"}
I set all my data in a channel entries tag in _data/_main
and get that data in _templates/_view
(and any subsequent embedded templates).
about/index:
{embed="_data/_main" url_title="{last_segment}"}
{embed="_templates/_view"}
_data/_main:
{exp:channel:entries channel="about" url_title="{embed:url_title}" ...}
{exp:stash:set}
{stash:title}{title}{/stash:title}
{stash:entry_id}{entry_id}{/stash:entry_id}
...etc
{/exp:stash:set}
{/exp:channel:entries}
_templates/_view:
...
<head>
<title>{exp:stash:title}</title>
...
</head>
<body>
<h1>{exp:stash:title}</h1>
...
</body>
...
is there a way to do this with twig? i’ve not been able to figure it out yet from the docs, wondering if anyone familiar with twig might know.
thanks
Just as jelle says, the way to do this is with Template Layouts. This video can help to get you started.
I have a bunch of twig template examples in this repository: ee7-coilpack (templates)
I have found the twig implementation to be really robust and it allows you be a lot more flexible with how you build your templates. If you are new to twig you might find the flexibility confusing.
Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.