I have my Field groups set up like so;
Trail
- title
- related_things [Playa]
Thing
- title
- content [Matrix]
- content_text [Wygwam]
- content_trail [Playa, assigns a Trail above]
When I edit a 'Thing', i'm adding multiple rows to the Matrix and assigning each {content_text} with a {content_trail}, which uses Playa:
.
However, some rows may have the same Trail assigned in the {content_trail}. This is not a problem, but in the template I would like the content displayed and grouped by the {content_trail}.
Here is my updated code using Stash;
{!-- Iterate over an array of unique Trails in the list --}
{exp:stash:set_list name="@:content_trail" parse_tags="yes" parse_depth="33"}
{!-- For each Trail output a data for the matching Trail --}
{exp:stash:get_list name='@:content'
orderby="content_trail"
sort="desc"
}
{!-- This is the content_text column from the content Matrix table --}
{stash:content_text}{content}{content_text}{/content}{/stash:content_text}
{stash:content_trail}{exp:playa:children col="content_trail"}{title}{/exp:playa:children}{/stash:content_trail}
{/exp:stash:get_list}
{/exp:stash:set_list}
{exp:stash:get_list name='@:content_trail' unique="yes"}
{!-- Get the unique Trail title --}
<h2>{content_trail}</h2>
{!-- Get all content_text Matrix rows for this Trail --}
{exp:stash:get_list:nested name="@:content" prefix="result" orderby="total" match="#^{content_trail}$#" against="content_trail"}
{content_text}
{/exp:stash:get_list:nested}
{/exp:stash:get_list}
What this is now doing is successfully getting the unique content_trail Playa data and displaying it all in one h2 tag like: Aviation TrailHeritage Trail, instead of creating two separate h2's. Also, it is not displaying the content_text rows that match the unique content_trail's.