2

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:

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'
      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.

5
  • 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
    Commented 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. Commented 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'. Commented 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. Commented 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. Commented Nov 14, 2013 at 15:34

1 Answer 1

0

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.
---------------------- --}
{exp:stash:set_list 
    name="@:content" 
    parse_tags="yes" 
    parse_depth="1" 
    trim="yes"
}
    {exp:channel:entries
        channel="ch_programs"
        entry_id="{segment_3}"
        dynamic="no"
        status="not closed"
    }

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

            {!--   playa column   --}
            {stash:trail}
                {mx:YOUR_PLAYA_COLUMN_NAME var_prefix="pl"}
                    {pl:title}
                {/mx:YOUR_PLAYA_COLUMN_NAME}
            {/stash:trail}

            {!--   another column   --}
            {stash:second}{mx:A_SECOND_MATRIX_COLUMN}{/stash:second}
            {!--   ...continue adding any other matrix variables you will need to output later...   --}

        {/YOUR_MATRIX_FIELD_NAME}

    {/exp:channel:entries}
{/exp:stash:set_list}


{!-- ---------------------- 
TWO - Iterate over an array of unique Trails in the list.
---------------------- --}
{exp:stash:set_list name="@:content_trail" parse_tags="yes"}
    {exp:stash:get_list 
        name='@:content'
        orderby="trail"
        sort="desc"
     }
        {stash:trail}{trail}{/stash:trail}
    {/exp:stash:get_list}
{/exp:stash:set_list}


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

    {!-- Get the unique Trail title --}
    <h2>{trail}</h2>

    {!-- 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>
        <p>etc...</p>

    {/exp:stash:get_list:nested}
{/exp:stash:get_list}
2
  • 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. :) Commented 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? Commented 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.