0

So how do i redirect to error/inferior template. I could add my template at the templates folder but thats not really nice. Is there something like {% exit 404 %} but for the inferior page?

2 Answers 2

4

Without knowing if this a channel, structure or single and no provided code I can't give you a detailed answer, but I think you are looking for Craft's redirect tag.

Redirect Tag

5
  • I want to redirect to inferior when the browser is unsupported, so i will redirect like a simple template there is no other way something like exit for the 404, right?
    – nickGR
    Sep 6, 2016 at 14:05
  • 4
    What you mean by "browser is unsupported"? Sep 6, 2016 at 14:11
  • I mean that i have a list of browser versions that my project supports and if the users browser is not one of them i will redirect him to the error/inferior template.So i just want to know if there is something specific for doing that or i'll have to do it with a redirect tag.
    – nickGR
    Sep 7, 2016 at 8:20
  • 1
    Craft out of the box can determine if the browser is mobile or not, but I don't think it can determine the browser/version without a plugin. I might be wrong here, any other peeps here can comment. Once determined, you can use Craft's redirect tag in the link above. Sep 7, 2016 at 12:27
  • Sounds like the OP already has a solution in place for figuring out if a certain browser is "supported" or not. If not, yes, there's the isMobileBrowser() method. There's also the Detect plugin, if you need to get specific :) Sep 7, 2016 at 16:51
0

I don't really know what you mean by an "inferior template" but I assume you're talking about either a scaled down version of your site or just a custom error template. Tons of ways to skin this cat, here are some options:

You can name your error/inferior template after a semi-appropriate HTTP status, and exit using that status (the below will load /templates/403.html, if it exists):

{% if browserNotSupported %}
    {% redirect 403 %}
{% endif %}

You can redirect to a different URI:

{% if browserNotSupported %}
    {% redirect '/some/other/url' %}
{% endif %}

You can also include a different template, e.g.

{% if browserNotSupported %}
    {% include '_inferior' %}
{% else %}
    {# Your other template or code #}
{% endif %}

...or you can use a ternary operation to extend a different layout:

{% extends browserNotSupported ? '_inferior' : '_layout' %}
{# Template code #}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.