4

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?

2 Answers 2

9

Exit tag is what you're looking for.

{% exit 403 %}
4
  • 1
    I actually didn't realise that worked for anything other than 404. My bad. Commented Jul 22, 2014 at 9:56
  • Next time you'll know :) Commented Jul 22, 2014 at 12:49
  • Every day's a school day. Commented Jul 22, 2014 at 13:44
  • @SteveAbraham Especially with Andris is the teacher.
    – Brad Bell
    Commented Jul 22, 2014 at 15:56
1

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...

1
  • 1
    Ignore my answer, do what Andris says, he's the man. Commented Jul 22, 2014 at 9:53

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.