Take the 2-minute tour ×
Craft CMS Stack Exchange is a question and answer site for administrators, end users, developers and designers for Craft CMS. It's 100% free, no registration required.

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

2 Answers 2

up vote 7 down vote accepted

Exit tag is what you're looking for.

{% exit 403 %}
share|improve this answer
1  
I actually didn't realise that worked for anything other than 404. My bad. –  Steve Abraham Jul 22 at 9:56
    
Next time you'll know :) –  Andris Sevcenko Jul 22 at 12:49
    
Every day's a school day. –  Steve Abraham Jul 22 at 13:44
    
@SteveAbraham Especially with Andris is the teacher. –  Brad Bell Jul 22 at 15:56
    
Thanks, don't know how I missed it :) –  noisysocks Jul 23 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
1  
Ignore my answer, do what Andris says, he's the man. –  Steve Abraham Jul 22 at 9:53

Your Answer

 
discard

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.