1

I want to display multiple lists of entries on the same page, but with entries that have the same custom filed grouped together. I'm not able to use categories to do this and wondered if it would be possible to use Stash to achieve the desired results. This is along the lines of what I'm trying to achieve:

{exp:channel:entries channel='tour' disable="category_fields|member_data" show_future_entries="yes" orderby="tour_date_start" sort="asc" search:tour_type="tour"}
                    <div class="unit3">
                        <a href="{url_title_path='tours/'}">
                        <div class="unit1 unitpadding grey overview">
                            <h3>{tour_name}</h3></a>
                            <ul>
                                <li><a href="{site_url}tours/{url_title}">{tour_date_start format="%j %F"} &ndash; {tour_date_end format="%j %F %Y"}</a>
                                </li>
                                <!--alternative tour dates to be outputted here if entries have the same {tour_code_short}->                                    
                                <li><a href="{site_url}tours/{url_title}">{tour_date_start format="%j %F"} &ndash; {tour_date_end format="%j %F %Y"}</a>{/alternative_tour_dates}
                                </li>
                                <!-- end alternative tour dates -->
                            </ul>
                        </div>
                    </div>
{/exp:channel:entries}

I feel like this might work with stash, but am not sure the best way to approach it? Could anyone offer any advice or guidance? Thanks.

1

You can use the match and against parameters to filter a list by the value of one or more columns.

{!-- set the list --}
{exp:stash:set_list name="groceries"}

   {stash:title}Cox Apple{/stash:title}
   {stash:color}green{/stash:color}

   {stash:title}Jazz Apple{/stash:title}
   {stash:color}yellow{/stash:color}

   {stash:title}Banana{/stash:title}
   {stash:color}yellow{/stash:color}

   {stash:title}Brocoli{/stash:title}
   {stash:color}green{/stash:color}

   {stash:title}Pepper{/stash:title}
   {stash:color}red{/stash:color}

{/exp:stash:set_list}

{!-- get all yellow groceries --}
{exp:stash:get_list name="groceries" match="#^yellow$#" against="color"}
    {title},   
{/exp:stash:get_list}

This page in the wiki has a more advanced example of the technique, uisng a custom index to match against multiple columns:

https://github.com/croxton/Stash/wiki/Filtering%20lists%20with%20match%20against

1
  • Hi Mark thanks again for you help. I can see that this should work, and have implemented it as suggested, the problem I have is that the data that I'm trying to pull in ie the color that I want to sort by is dynamic. So I can't predict what the options will be to sort from? Is it possible to match against a field, say {stash:color}{color}{/stash:color} and then in the get_list match="#^{color}$#" ? – Erbert Aug 12 '14 at 14:06
0

You could try the 'Group By' extension, this effectively adds a SQL style 'GROUP BY' parameter to the channel entries tag - https://github.com/nathanpitman/group_by.ext.ee_addon

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.