2

This seems to be linked to the issue discussed on this question however it's using cache tags instead of parse and I'm redirecting to a 404.

My code is as follows:

{exp:stash:cache name="page"}

  {exp:channel:entries
    channel="post"
    disable="categories|category_fields|member_data|pagination|trackbacks"
    require="yes"
  }

    {if no_results}{redirect="pages/404"}{/if}

  {/exp:channel:entries}

{/exp:stash:cache}

I'm accessing this template from the following URI - /posts/test-post-that-doesnt-exist

This post doesn't exist, however the template still renders and does not redirect as you'd expect with the no_results tag.

Following the idea on this question I added an empty no_results and it redirects correctly.

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

It smells like a prefix issue, if I removed the stash:cache tags it redirects correctly.

Has anyone else has this issue? Is there a work around? Am I missing something (have tried prefix and unprefix parameters on the stash:cache tag).

Ta

2

I'm not sure if this works with the {exp:stash:cache} tag or not, but you can try it:

{exp:stash:cache name="page" unprefix="my_prefix"}
    {exp:channel:entries
        channel="post"
        disable="categories|category_fields|member_data|pagination|trackbacks"
        require="yes"
    }
        {if my_prefix:no_results}{redirect="404"}{/if}
    {/exp:channel:entries}
{/exp:stash:set}
3
  • Thanks for the reply. I've tried the unprefix param, but it didn't make a difference. I have found some of the tags share params from other tags without being documented however not on this occasion. Feb 23 '14 at 14:42
  • 2
    Unprefix should definitely work in this situation, it's precisely what it is for. It was only added very recently though, make sure you are using the latest version of Stash. Changelog: github.com/croxton/Stash/wiki/Changelog Feb 24 '14 at 10:23
  • 1
    I've just updated (I was running 2.4.8) and unprefix works. It's good to know this is the what is should be used for as well. Thanks to you both! Feb 24 '14 at 11:25

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.