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
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.
-
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?– nickGRSep 6, 2016 at 14:05
-
4
-
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.– nickGRSep 7, 2016 at 8:20
-
1Craft 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 theDetect
plugin, if you need to get specific :) Sep 7, 2016 at 16:51
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 #}