3

This is more an A than a Q.

Last week I ran into no results / redirect problem with Stash and more precisely the EE's parsing order. The solution below worked for my case. I don't take credit for it as I found it either on the Devotee-forum for Stash or as a Gist someone was willing to share. I can't remember, after losing way to much time on this I didn't keep track. Anyway, thought I would share this as it may save others time.

On the template that collects the data...

{exp:stash:set 
parse_tags="yes" 
parse_conditionals="yes" 
parse_depth="2" 
no_results_prefix="nested"
}
    {exp:channel:entries 
    channel="YOURCHANNEL" 
    disable="categories|category_fields|member_data|pagination" 
    status="open" 
    dynamic="no"
    }

        // channel entry data stuff here...

        {if nested:no_results}
            {exp:stash:set_value name="no_results" value="true"}
        {/if} 

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

{embed="YOURTEMPLATEGROUP/YOURTEMPLATE"}

Note: parse_depth and no_results_prefix Stash parameters are necessary.

On the embed that outputs the data (the view)

{if {exp:stash:not_empty name="no_results"}}
  {exp:stash:unset name="no_results"}
  {redirect="home/404"}
{/if}
2
  • 3
    May want to put this in question/answer format and answer your own question, marking it as answered. – notacouch Apr 3 '14 at 15:11
  • Agreed this should be in Q/A format. It has an answer and should not show up in unanswered questions. – Steve Buzonas Jul 10 '14 at 18:49
1

Since this question has been answered above, but hasn't yet been added as answer, I'll answer it here, so it can be marked as answered and corrected.

I ran into the same issue but solved it a little bit differently. Where the answer above redirects in the template, I did the redirection immediately in the template, rather than the embedded snippet. Like this:

{exp:stash:set parse_tags="yes" parse_depth="2" unprefix="detail"}
     {exp:channel:entries 
          channel="channel_entries" 
          status="open" 
          limit="1"       
          disable="pagination|member_data|categories|category_fields"          
          require_entry="yes"}

             {if detail:no_results}
                {redirect="404"}
             {/if}

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

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.