1

This one's got me.

I'm using Stash to capture a list of entries into a set_list. I want to get this list in two different areas on the page with different categories. If I were simply trying to display 2 different categories, match/against would work. However, what I'm trying to do seems to be a little more complicated. Here's what I want:

  1. In the first get_list, I want to show entries from all but one category.
  2. In the second get_list, I want to show entries from the the single category I excluded in the first list

The exact scenario is that I would like one list to show all articles, and the other list to show only announcements.

Here's what I'm starting off with:

{!-- Articles --}
{exp:stash:set_list name="articles" parse_tags="yes"}
    {exp:channel:entries
        channel="news"
        dynamic="no"
        orderby="sticky|entry_date"
        sort="desc|desc"
        sort_type="numeric|numeric"
        disable="pagination|member_data|category_fields"
    }
        {stash:sticky}{sticky}{/stash:sticky}
        {stash:title}{title}{/stash:title}
        {stash:summary}{article_summary}{/stash:summary}
        {stash:date}{entry_date}{/stash:date}
        {stash:url}{page_url}{/stash:url}
        {stash:image}{article_featured_image}{/stash:image}

        {!-- Get the category_id so we can match against them --}
        {stash:category_id}{categories}{category_id}{/categories}{/stash:category_id}
    {/exp:channel:entries}
{/exp:stash:set_list}

So, that gives me my list of all articles. For my second list, it's as simple as using match/against to only show announcments:

{exp:stash:get_list name="articles" match="#^13#" against="category_id"}
    <article>
        <p><a href="{url}"><i class="ss-icon ss-newspaper"></i> <span class="meta">{date format="%M %d, %Y"}</span> {title}</a></p>
    </article>
{/exp:stash:get_list}

It's the first list where I'm stumped. How do I capture all entries except for those in category 13 without having to make another channel entries call?

I know I could just create 2 separate set_lists with 2 separate channel entry calls. One which has category="not 13" and another with category="13".

I also thought I could wrap 2 set_lists in the {cateogries} tag and, again use show="13" and show="not 13", but I don't see a way to do that without repeating my stash variable setters.

How do I keep this at a single channel entry call and keep it DRY?

Update:

romans-8-31-39 pointed out a feature I didn't know existed, which was to NOT match a pattern when filtering a list. That answer is technically correct. When I went to implement that, I realized I'm already using match/against on my first list to match against sticky entries.

Would this be a use case for the stash technique outlined here? I'm having a hard time wrapping my head around the technique.

  • It pains me, but this is where I am until I figure out a better way. pastie.org/9375301 – jthomas Jul 10 '14 at 20:37
  • I feel like I could use the pattern described here for the first list: github.com/croxton/Stash/wiki/… However, I'm already using match/against to filter on sticky entries in the first list, and I don't know of a way to use multiple columns in match/against. – jthomas Jul 10 '14 at 21:05
  • Can you add the match/against from the first list you're using for sticky? – Romans-8---31-39 Jul 10 '14 at 21:29
  • {exp:stash:get_list name="articles" match="#^y$#" against="sticky"} – jthomas Jul 10 '14 at 21:30
  • Grr. Almost got it working using the "tracking" tecnnique at the bottom of the fitering lists technique, but the catch is that you can't use both tracking and match/against. – jthomas Jul 10 '14 at 21:44
1

For the first list I think you're just looking for a regex that does NOT match the category you want to exclude. I haven't tested this, but try the regular expression

^(?!13$)

So you would end up with:

{exp:stash:get_list name="articles" match="#^(?!13$)#" against="category_id"}
...

to see if that finds all items in your articles list that are not category 13. (Updated, changed regex after test run.)

  • That does answer my question. I should (and will) clarify, I'm already using the match/against to filter on {sticky}. I think what I need is this: github.com/croxton/Stash/wiki/… – jthomas Jul 10 '14 at 21:13

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.