<p>Bit of a shot in the dark here, but it might be worth having a look at the <a href="http://buildwithcraft.com/docs/templating/header" rel="nofollow">header tag</a>, see if you can get that to do what you need...</p>

CC BY-SA 3.0
2014-07-22T09:53:17.203Z
Ignore my answer, do what Andris says, he's the man.
Steve Abraham
CC BY-SA 3.0
2014-07-22T08:34:57.180Z
2014-07-22T08:34:57.180Z
Steve Abraham
<p><a href="http://buildwithcraft.com/docs/templating/exit" rel="noreferrer">Exit tag</a> is what you're looking for.</p>

<pre><code>{% exit 403 %}
</code></pre>

CC BY-SA 3.0
2014-07-22T09:56:02.160Z
I actually didn't realise that worked for anything other than 404. My bad.
Steve Abraham
CC BY-SA 3.0
2014-07-22T12:49:07.723Z
Next time you'll know :)
Andris Sevcenko
CC BY-SA 3.0
2014-07-22T13:44:07.263Z
Every day's a school day.
Steve Abraham
CC BY-SA 3.0
2014-07-22T15:56:43.847Z
@SteveAbraham Especially with Andris is the teacher.
Brad Bell
CC BY-SA 3.0
2014-07-22T09:52:13.197Z
2014-07-22T15:48:19.233Z
2014-07-22T15:48:19.233Z
Andris Sevcenko
<p>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.</p>

<p>For example:</p>

<pre><code>{% if not user %}
    {% respond 403 %}
{% endif %}
</code></pre>

<p>Is something like this built in?</p>

<templating>
How can I return HTTP 403 from a template?
# How can I return HTTP 403 from a template?

(Asked by: username_0 on 2014-07-22)

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?

**Tags:** templating


---

## 2 answers

### Answer by username_2 on 2014-07-22. Score: 9 | Accepted answer

Exit tag is what you're looking for.
{% exit 403 %}

> **Comments:**
> **username_1**: I actually didn't realise that worked for anything other than 404. My bad.  
> **username_2**: Next time you'll know :)  
> **username_1**: Every day's a school day.  
> **username_3**: @SteveAbraham Especially with Andris is the teacher.  

---

### Answer by username_1 on 2014-07-22. Score: 1

Bit of a shot in the dark here, but it might be worth having a look at the [header tag](http://buildwithcraft.com/docs/templating/header), see if you can get that to do what you need...

> **Comments:**
> **username_1**: Ignore my answer, do what Andris says, he's the man.  

---

