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?

9

Exit tag is what you're looking for.

{% exit 403 %}
  • 1
    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
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
    Ignore my answer, do what Andris says, he's the man. – Steve Abraham Jul 22 '14 at 9:53

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.