I have my Field groups set up like so;


  • title
  • related_things [Playa]


  • 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:

enter image description here.

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'
        {!-- This is the content_text column from the content Matrix table --}
        {stash:content_trail}{exp:playa:children col="content_trail"}{title}{/exp:playa:children}{/stash:content_trail}

{exp:stash:get_list name='@:content_trail' unique="yes"}
    {!-- Get the unique Trail title --}
    {!-- 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"}


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.

  • 1
    Look at Stash Module (github.com/croxton/Stash). Will most likely help you do what you want. Here are the docs: github.com/croxton/Stash/wiki
    – Anna_MediaGirl
    Nov 13, 2013 at 16:51
  • Thanks Anna. I'm familiar with Stash and have used it extensively, but i'm still somewhat stuck on how to proceed. Nov 13, 2013 at 22:42
  • If you do use Stash, you could do something similar to this: devot-ee.com/add-ons/support/stash/viewthread/10127 but instead of 'distance' being unique in that example you would use iterate over 'content_trail'. Nov 14, 2013 at 3:34
  • Thanks @Romans-8---31-39. I've added some updated code using the Stash example that gets me part way there, along with a new issue. Nov 14, 2013 at 10:08
  • Instead of increasing parse depth in the first part and running playa, try setting all that before -- leaving you with only the {stash:content_trail}{your_already_set_stash_var}{/stash:content_trail} in your example. See how the first post set the first stash variable of 'distance' (Mark just recommended he combine his first 2 set lists into one). Confusing, but it looks like you're almost there. Nov 14, 2013 at 15:34

1 Answer 1


I went ahead and messed around with what you had done so far, and you should be able to use the following to get started. It works when I tested it, but you'll of course need to put your own field names in. (Based on this support thread: "Simulating 'group by' filtering and sorting.")

{!-- ---------------------- 
ONE -  Grab all possible trails, and other variables needed.
---------------------- --}
        status="not closed"

        {!--   matrix   --}
        {YOUR_MATRIX_FIELD_NAME var_prefix="mx"}

            {!--   playa column   --}
                {mx:YOUR_PLAYA_COLUMN_NAME var_prefix="pl"}

            {!--   another column   --}
            {!--   ...continue adding any other matrix variables you will need to output later...   --}



{!-- ---------------------- 
TWO - Iterate over an array of unique Trails in the list.
---------------------- --}
{exp:stash:set_list name="@:content_trail" parse_tags="yes"}

{!-- ---------------------- 
THREE - Output with formatting.
---------------------- --}
{exp:stash:get_list name='@:content_trail' unique="yes"}

    {!-- Get the unique Trail title --}

    {!-- Get all other Matrix data you've set that match this Trail --}
    {exp:stash:get_list:nested name="@:content" match="#^{trail}$#" against="trail"}

        {!--   ...output any other variables you have set with formatting...   --}
        <p>Second variable: {second}</p>

  • Genius. Thank you so much. Just need to be able to figure how to get the url_title from the playa field now and I'm done. :) Nov 14, 2013 at 22:39
  • Hey @Romans-8---31-39. If I needed to get other data from the Playa relationship, how would i get that in this instance? Nov 26, 2013 at 15:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.