<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>

CC BY-SA 4.0
2021-02-15T10:41:23.697Z
2021-02-15T10:41:23.697Z
Oli
<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>

CC BY-SA 4.0
2021-02-15T12:04:49.663Z
2021-02-15T12:04:49.663Z
Matt Wilcox
<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>

CC BY-SA 4.0
2021-02-15T10:44:56.363Z
2021-02-15T10:44:56.363Z
MisterMike
<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>

<templating>
Stop specific Twig template from rendering anything
# 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), username_1's answer is what you might want to look at.


---

