0

I'm having two separate no_results problems with Stash.

First, if I visit a page that doesn't have a corresponding last segment using the code below, the page displays stuff like {2e1acf078c376a119e542c46883a119f33292409} and nothing else:

{stash:embed name="layouts:global"}

{exp:channel:entries
    channel="site"
    url_title="{last_segment}"
    disable="categories|member_data|pagination|trackbacks"
    require_entry="yes"
}
    {if no_results}{redirect="404"}{/if}

    {exp:stash:set name="st_content" type="snippet"}
        {body}
    {/exp:stash:set}

{/exp:channel:entries}

Then in another template, the switchee_no_results doesn't redirect to the 404 template, it just displays a page with a blank content area. I've also tried just plain no_results and also settings a prefix parameter on the get_list tag.

{stash:embed name="layouts:global"}

{exp:stash:set_list
    name="project_list"
    parse_tags="yes"
}

    {exp:channel:entries
        channel="projects"
        disable="member_data|pagination|trackbacks"
        {if segment_2=="detail"}url_title="{last_segment}"{/if}
    }

        {stash:project_url_title}
            {url_title}
        {/stash:project_url_title}

        {stash:project_detail}
            <h2>{title}</h2>
            {project_text}
        {/stash:project_detail}

    {/exp:channel:entries}

{/exp:stash:set_list}

{exp:stash:set name="st_content" type="snippet"}

    {exp:switchee variable="{segment_2}" parse="inward"}

        {!-- Landing page --}
        {case value=""} … {/case}

        {!-- Detail page --}
        {case value="detail"}

        {exp:stash:get_list
            name="project_list"
            match="#{segment_3}#"
            against="project_url_title"
            parse_conditionals="yes"
            parse_tags="yes"
            process="end"
        }

        {if switchee_no_results}{redirect="404"}{/if}

        {project_detail}

        {/exp:stash:get_list}

        {/case}

    {/exp:switchee}

{/exp:stash:set}

Anyone know why that might be?

1 Answer 1

2

The short answer is to use a full template_group/template path to your 404, e.g.

{redirect="site/404"}

I explained the reason why here: Strange Stash & redirect issue

EDIT:

Since this post was made I have added a new tag {exp:stash:not_found} to help with situations where the no_results condiotonals are nested inside other tags:

https://github.com/croxton/Stash/wiki/%7Bexp%3Astash%3Anot_found%7D

Note that the best place to use {if no_results}... is on the tag that you are trying to capture data from.

4
  • That solves the first part of the question (partly), but not the second in the switchee_no_results. And I say partly because when using site/404, you actually get redirected to that URL rather than the 404 template displaying at the broken URL which is the behaviour exhibited when just specifying redirect="404" and which I believe is necessary for the URL to be recorded as a 404 rather than a 301 in the search engines.
    – Tyssen
    Dec 4, 2013 at 20:45
  • I'm adding a comment here so i can watch for the solution because I'm having a similar issue. If no results tag pair is resulting in a blank page body in the template rather that showing the actual 404 page and I'm struggling to determine why. I have require_entry="yes" and url_title="{last_segment}" along with dynamic="no" and {if no_results}{redirect_404}{/if} tag pair inside my stashed entries loop but I still get an empty template rather than getting redirected to my 404 template. Nov 12, 2015 at 17:10
  • @jean See updated post above Nov 12, 2015 at 19:21
  • I'm still having no luck with it, Mark. I can put whatever I want into the URL and as long as there is a matching template group is segment1 I get a page served. Nov 13, 2015 at 14:48

This site is temporarily in read-only mode and not accepting new answers.

Not the answer you're looking for? Browse other questions tagged .