Answers.Body: <p>Depending on what you exactly need to happen, the <code>{% exit %}</code> (<a href="https://craftcms.com/docs/3.x/dev/tags.html#exit" rel="nofollow noreferrer">docs</a>) tag my be an option for you.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-02-15T10:41:23.697Z
Answers.LastActivityDate: 2021-02-15T10:41:23.697Z
Answers.UserDisplayName: Oli
Answers.Body: <pre><code>{% if not currentUser %}{# or whatever #}
      {% exit 401 %}{# Or whatever HTTP status appropriate template it should be #}
  {% endif %}
  
  ... the rest of your template ...
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-02-15T12:04:49.663Z
Answers.LastActivityDate: 2021-02-15T12:04:49.663Z
Answers.UserDisplayName: Matt Wilcox
Answers.Body: <p>If this related to an entire twig template, you could include it inside an if statement:</p>
  <pre><code>{% if not devMode %}{% include '_includes/google-analytics.twig' -%}{%  endif %}
  </code></pre>
  <p>If you need to exit a twig template early (based on some value), Oli's answer is what you might want to look at.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-02-15T10:44:56.363Z
Answers.LastActivityDate: 2021-02-15T10:44:56.363Z
Answers.UserDisplayName: MisterMike
Body: <p>If i want specific template to stop from rendering anything, I use <code>if</code>:</p>
  <pre><code>{% if something %}
  HTML markup...
  {% endif %}
  </code></pre>
  <p>This however requires wrapping whole Template in <code>if</code> which is not ideal for readbility.</p>
  <p>Is there maybe some kind of Twig function which when used stops rendering template in which it is used? Like this:</p>
  <pre><code>{% if something %}
      {% do stopRendering() %}
  {% endif %}
  
  HTML markup (will show up if we didnt stopped rendering)...
  </code></pre>
  
Tags: <templating>
Title: Stop specific Twig template from rendering anything
ThreadText: # Stop specific Twig template from rendering anything
  
  (Asked by: username_0 on 2021-02-15)
  
  If i want specific template to stop from rendering anything, I use `if`:
  
  ```
  {% if something %}
  HTML markup...
  {% endif %}
  
  ```
  
  This however requires wrapping whole Template in `if` which is not ideal for readbility.
  
  Is there maybe some kind of Twig function which when used stops rendering template in which it is used? Like this:
  
  ```
  {% if something %}
      {% do stopRendering() %}
  {% endif %}
  
  HTML markup (will show up if we didnt stopped rendering)...
  
  ```
  
  **Tags:** templating
  
  
  ---
  
  ## 3 answers
  
  ### Answer by username_1 on 2021-02-15. Score: 1
  
  Depending on what you exactly need to happen, the `{% exit %}` ([docs](https://craftcms.com/docs/3.x/dev/tags.html#exit)) tag my be an option for you.
  
  
  ---
  
  ### Answer by username_2 on 2021-02-15. Score: 1
  
  ```
  {% if not currentUser %}{# or whatever #}
      {% exit 401 %}{# Or whatever HTTP status appropriate template it should be #}
  {% endif %}
  
  ... the rest of your template ...
  
  ```
  
  
  ---
  
  ### Answer by username_3 on 2021-02-15. Score: 1
  
  If this related to an entire twig template, you could include it inside an if statement:
  
  ```
  {% if not devMode %}{% include '_includes/google-analytics.twig' -%}{%  endif %}
  
  ```
  
  If you need to exit a twig template early (based on some value), Oli's answer is what you might want to look at.
  
  
  ---
  
  