January 9, 2014

Simple ExpressionEngine Stash Parse Order

Stash is a great addition to the ExpressionEngine toolkit, but sometimes the parse order can get a little confusing. One great thing about Stash is the ability to set variables at the top of a template that can be used later on in your code. This allows you to keep a nice separation between the data and the template itself. I’m not going to be talking about template partials at all as there are a bunch of great articles about that floating around. This post is just outlining a specific problem and it’s solution.

If you need to use a Stash variable that was created within a Channel Entries loop earlier in a template as a parameter in a Channel Entries loop, you can delay the parse order of the second Channel Entries loop such that the variable gets set prior to the loop being executed. For example if you got a list of entry IDs of related entries (from Relationships or Playa) you could put those in the entry_id parameter and then print out the entries in the correct order. This could be used for categories, statuses, search values, whatever.

Nest ExpressionEngine Stash loop

There are always a bunch of ways to do something in EE but this method has proven handy in several recent builds to get around needing embeds or other more complex nesting.

{exp:stash:parse process="end"}
  {exp:channel:entries channel="XXX" fixed_order="{stash:places}" entry_id="{stash:places}" dynamic="no"}