0

It seems many users have issues with Stash and no_results, but as far as I can tell, nobody is trying to do this scenario. Please forgive me if I missed something.

I would like to redirect users to a page if they stumble on the URL for a specific entry for which they do not have permissions, determined by some custom fields specified in {lv_permissions}. To make permissions work, I needed to wrap the entries block in exp:stash:parse process="end", but that seems to have killed my {if no_results}{redirect="site/1"}{/if} line. No redirect occurs, though the content also does not show up, which is good.

Does anyone have an explanation for this behavior and some proper syntax?

{lv_permissions}
{exp:stash:parse process="end"}
  {exp:channel:entries
    channel="my_channel"
    require_entry="yes"
    limit="1"
    {stash:permissions}
  }
    {if no_results}{redirect="site/1"}{/if}
  {/exp:channel:entries}
{/exp:stash:parse}

I tried the no_results_prefix concept, but that doesn’t seem to work for exp:stash:parse.

2

I found if I repeat the no_results line, the redirect works. If I just write it once, no redirect occurs, though the content also does not show up, which is good.

Does anyone have an explanation for this behavior?

Navigating to a URL I should not have access to as a logged in user redirects me to /site/1 using this:

{lv_permissions}
{exp:stash:parse process="end"}
  {exp:channel:entries
    channel="my_channel"
    require_entry="yes"
    limit="1"
    {stash:permissions}
  }
    {if no_results}{/if}
    {if no_results}{redirect="site/1"}{/if}
  {/exp:channel:entries}
{/exp:stash:parse}

This works, but clearly it’s wonky.

| improve this answer | |
  • sad but true, thx for this hack - working for me. – Richard Frank Jul 17 '14 at 14:26
0

In my opinion you should rethink your approach a bit here. Whilst it's probably possible to cobble together some esoteric convoluted template code to deal with permissions, it would be much safer and more maintainable if you built a custom add-on to handle your exact needs.

Specifically, you could build an extension based on the channel_entries_tagdata_end hook that makes the necessary checks and redirects accordingly.

| improve this answer | |
  • Hi there, I started to explore this option, but ran into problems because I need this to work two ways. The above example is on individual entry pages for redirecting, but I also have search results pages that relies on the same technique to filter out entries user shouldn't see. I can't seem to find a way to use an extension to filter the full result set of a channel:entries tag and return a possibly reduced number of entries. Do you have any pointers for this? Much appreciated! – Charlie Gorichanaz Apr 4 '14 at 9: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.