Craft CMS Stack Exchange is a question and answer site for administrators, end users, developers and designers for Craft CMS. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm building a rough JSON API using normal Craft templates (i.e. rendering the JSON with Twig) but would like to be able to return HTTP 403 to unauthenticated requests.

For example:

{% if not user %}
    {% respond 403 %}
{% endif %}

Is something like this built in?

share|improve this question
up vote 7 down vote accepted

Exit tag is what you're looking for.

{% exit 403 %}
share|improve this answer
I actually didn't realise that worked for anything other than 404. My bad. – Steve Abraham Jul 22 '14 at 9:56
Next time you'll know :) – Andris Sevcenko Jul 22 '14 at 12:49
Every day's a school day. – Steve Abraham Jul 22 '14 at 13:44
@SteveAbraham Especially with Andris is the teacher. – Brad Bell Jul 22 '14 at 15:56
Thanks, don't know how I missed it :) – noisysocks Jul 23 '14 at 5:15

Bit of a shot in the dark here, but it might be worth having a look at the header tag, see if you can get that to do what you need...

share|improve this answer
Ignore my answer, do what Andris says, he's the man. – Steve Abraham Jul 22 '14 at 9:53

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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