We use cookies to improve your experience. No personal information is gathered and we don't serve ads. Cookies Policy.

ExpressionEngine Logo ExpressionEngine
Features Pricing Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University
Log In or Sign Up
Log In Sign Up
ExpressionEngine Logo
Features Pro new Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University Blog
  • Home
  • Forums

Learning Twig coming from Stash

How Do I?

wagonheart's avatar
wagonheart
2 posts
about 2 years ago
wagonheart's avatar wagonheart

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

       
jelle's avatar
jelle
87 posts
about 2 years ago
jelle's avatar jelle

Don’t really know wether that’s doable with Twig, but i think with Template Layouts you can achieve the same, without an addon and without embeds

       
Nelly's avatar
Nelly
94 posts
about 2 years ago
Nelly's avatar Nelly

Just as jelle says, the way to do this is with Template Layouts. This video can help to get you started.

       
Jared Chesebro's avatar
Jared Chesebro
15 posts
about 2 years ago
Jared Chesebro's avatar Jared Chesebro

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.

       
policydining's avatar
policydining
1 posts
about 2 years ago
policydining's avatar policydining

Thanks a lot.

       
Dillan2314's avatar
Dillan2314
1 posts
one year ago
Dillan2314's avatar Dillan2314

When I was learning Twig after working with Stash, the transition was smoother than expected. The key was to grasp Twig’s template inheritance and logic control. If you’re tackling something complex, breaking it down with basic Twig tags first really helps. Also, while learning new syntax, don’t forget to explore resources outside coding—like improving your writing skills. For example, browsing through quality academic nursing papers examples like those on can provide clarity on structuring content effectively. This way, you enhance both coding and communication, which is essential when presenting ideas clearly in templates or documentation.

? 1
       

Reply

Sign In To Reply

ExpressionEngine Home Features Pro Contact Version Support
Learn Docs University Forums
Resources Support Add-Ons Partners Blog
Privacy Terms Trademark Use License

Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.