0

EE 2.10.1 Playa 4.5.2 Stash 2.6.7

I'm building out a particularly complex single entry page and can't seem to wrap my head around how to approach what needs to be done.

I have a Trips channel with two playa fields Related Outpost and Related Activity. On the individual trip page I need to list all trips that are in the same outpost (reverse relationship) and sort them by Activity.

So Trip A takes place at the Green Outpost. I need to show all trips that also take place at the Green Outpost and then sort/filter like this:

Rafting (activity)

  • trip a
  • trip b
  • trip c

Hiking (activity)

  • trip d
  • trip e

I know it's not possible to filter/search by a playa field natively, but would this be possible using Stash and if so, where would I start with this?

Currently I have the following, stripped down template, where I suspect that each Activity (Rafting etc) would be an embed

{exp:channel:entries channel="trips"}

        {trip_outpost}<h2 class="text-center trip-outpost">{title}</h2>{/trip_outpost}

    <h3>Rafting</h3>
        <div class="trip">
            <h4>Trip Title</h4>
            Trip Details Here
        </div>

        <div class="trip">
            <h4>Trip Title</h4>
            Trip Details Here
        </div>

        <div class="trip">
            <h4>Trip Title</h4>
            Trip Details Here
        </div>

    <h3>Hiking</h3>
        <div class="trip">
            <h4>Trip Title</h4>
            Trip Details Here
        </div>

        <div class="trip">
            <h4>Trip Title</h4>
            Trip Details Here
        </div>

{/exp:channel:entries}
1

You could use {exp:playa:coparents} to list other parent entries (trips) that share the same child (outpost). Then within that loop, list the activity associated with each trip (I'm assuming you have the field set to only select one activity); we'll capture the related trips as a Stash list, and also create a second list of all the activities in the related trips.

Then we need to loop over the unique activities in the list and output trips that match each activity. We can do that with a nested Stash get_list:

{exp:channel:entries channel="trips"}

    {exp:stash:set_list name="trips" parse="yes" parse_depth="3"}
        {exp:playa:coparents field="trip_outpost" var_prefix="trip"}
            {stash:title}{trip:title}{/stash:title}
            {stash:activity}@{exp:playa:children entry_id="{trip:entry_id}" field="trip_activity" var_prefix="activity"}{exp:stash:append_list name="activities"}{stash:activity}{activity:title}{/stash:activity}{/exp:stash:append_list}{activity:title}@{/exp:playa:children}{/stash:activity}
        {/exp:playa:coparents}
    {exp:stash:set_list}

{/exp:channel:entries}  

{exp:stash:get_list name="activities" unique="activity" process="end"}
    <h3>{activity}</h3>
    <ul>
    {exp:stash:get_list:trips name="trips" match="#\Q@{activity}@\E#" against="activity" prefix="trip"}
        <li>{trip:title}</li>
    {/exp:stash:get_list:trips}
    </ul>
{/exp:stash:get_list}
| improve this answer | |
  • THanks Mark, I'll be trying this code out tomorrow - have some other work that needs to be done first. Will keep you posted. – CreateSean Feb 2 '16 at 16:04
  • Mark, Just got back to this and activity is a multi-select as there can be more than one activity on a trip such as rafting and ziplining or rafting and camping. Does that change anything? – CreateSean Feb 19 '16 at 22:15
  • I've updated the answer above to account for multiple activities using @ as a delimiter (this is arbitrary, it could be anything). – Mark Croxton Feb 22 '16 at 9:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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