Answers.Body: <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>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-07-22T09:53:17.203Z
Answers.Text: Ignore my answer, do what Andris says, he's the man.
Answers.UserDisplayName: Steve Abraham
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-07-22T08:34:57.180Z
Answers.LastActivityDate: 2014-07-22T08:34:57.180Z
Answers.UserDisplayName: Steve Abraham
Answers.Body: <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>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-07-22T09:56:02.160Z
Answers.Text: I actually didn't realise that worked for anything other than 404. My bad.
Answers.UserDisplayName: Steve Abraham
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-07-22T12:49:07.723Z
Answers.Text: Next time you'll know :)
Answers.UserDisplayName: Andris Sevcenko
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-07-22T13:44:07.263Z
Answers.Text: Every day's a school day.
Answers.UserDisplayName: Steve Abraham
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-07-22T15:56:43.847Z
Answers.Text: @SteveAbraham Especially with Andris is the teacher.
Answers.UserDisplayName: Brad Bell
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-07-22T09:52:13.197Z
Answers.LastActivityDate: 2014-07-22T15:48:19.233Z
Answers.LastEditDate: 2014-07-22T15:48:19.233Z
Answers.UserDisplayName: Andris Sevcenko
Body: <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>
  
Tags: <templating>
Title: How can I return HTTP 403 from a template?
ThreadText: # 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](http://buildwithcraft.com/docs/templating/exit) 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**: @username_1 Especially with username_2 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 username_2 says, he's the man.  
  
  ---
  
  