I have an empty stash list, as expected. I need to output some alternative content if the list is empty. I've tried using conditionals and {count} but to no prevail.

Any ideas how I can do this. I am using Stash and Expresso Store. I need to allow users to seamlessly switch between purchased and purchased products.

Any help, greatly appreciated

Here is my list

{exp:store:orders member_id='CURRENT_USER' order_by='order_date' sort='desc'}
    {exp:channel:entries entry_id="{entry_id}" channel="series"}
        {exp:stash:set_list name="series_list" parse_tags="yes" parse_depth="3" context="{url_title}"}
                {exp:stash:set_list:nested name="series_list_episodes" parse_tags="yes" context="{entry_id}"}

And here is the output:

{exp:stash:get_list name="series_list" context="{segment_3}"}
    {!-- if no results/list empty load another product --}
    {!-- chuff removed --}
    {exp:stash:get_list:nested name="series_list_episodes" context="{item_entry_id}" prefix="nested" }
                {!-- bla bla this all works nicely, just stash variables used in the embed --}


A little background to my issue.

I am building a ecommerce site that gives users access to some streaming video content.

From within one template I need to be able to list products which have been purchased and products which haven't been purchased.

With the list above, I was hoping to return some content based on the {segment_3} value, if there is no content, so rather than using the exp:store:orders loop, I'd use the standard channel entries loop with the url_title set to {segment_3} (i've not coded this part yet, Just at the stage where I need to return 'something' if the list returns nothing.

  • What exactly is the problem? {if no_results} should work fine with get_list and I see you're aware of prefix=. So is your issue how to display alternative content when you have nothing to work with? – notacouch Apr 23 '14 at 23:29
  • That's right. Nothing is returned by the list in certain "contexts", which I am expecting, I need to be able to output some alternative content for this "context". I've tried using no_results but to no prevail. – magicspon Apr 24 '14 at 8:45
  • When you say no_results isn't working, can you be more specific: is nothing being output between the no_results tags? – Romans-8---31-39 Apr 24 '14 at 14:35
  • As Romans asked, by to no prevail do you mean you couldn't get the no_results condition to output anything or having no_results is not useful enough to you to display something contextual? – notacouch Apr 24 '14 at 14:55
  • Nothing is returned, no markup, no nothing. – magicspon Apr 24 '14 at 16:05

If your {exp:stash:get_list} tag is wrapped by another tag pair, then commonly used template variables like no_results are parsed for the parent tag by EE.

Add the prefix="my_prefix" parameter to provide a namespace, and use the prefix like this:

{if my_prefix:no_results}...{/if}

There are a few other ways to check that a list exists (or is empty):

With a conditional using {exp:stash:list_count}:

{if {exp:stash:list_count name="my_list"} > 0}

With a conditional using {exp:stash:is_empty} or {exp:stash:not_empty}:

{if {exp:stash:not_empty name="my_list"}}

Or with Switchee:

{exp:switchee variable="stash:my_list" parse="inward"}
  {case value="#^\S+#"}
     List exists
  {case default="yes"}
     Doesn't exist

Use either the {if my_prefix:no_results} or the Switchee methods if you intend to process another tag when the list is empty.

| improve this answer | |
  • Hi Mark, Thanks for your response. I've tried each of the methods but I'm still not getting anything returned when checking on an empty list. I've now used some php to get the desired results, then used stash later on. I'll post my method in an answer to this. Anyhow, thanks for Stash, ruddy lovely stuff. – magicspon Apr 25 '14 at 22:43

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.