<p>Another way would be to use:</p>

<pre><code>{% include [
    '_globals/footer-' ~ craft.request.lastSegment,
    '_globals/footer'
] %}
</code></pre>

<p>You'd then have your regular <code>footer.twig</code> for all pages, but you could have a <code>footer-404.twig</code> that would just render on the 404 page.</p>

<p>Note: I think the previous solutions are better, but variety of solutions is always good, right?</p>

CC BY-SA 3.0
2017-04-06T11:32:45.027Z
2017-04-06T11:32:45.027Z
ianp
<p>Just in case anyone stumbles across this and is using craft 3 "craft.request.firstSegment" is now deprecated in favour of "craft.app.request.segments|first". So this is now:</p>

<pre><code>{# Includes the footer on all pages except homepage, contact and 404 #}
{% set exclusions = ['', 'contact', '404'] %}
{% if craft.app.request.segments|first not in exclusions  %}
    {% include '_footer'%}
{% endif %}
</code></pre>

CC BY-SA 4.0
2018-10-03T22:43:42.083Z
2018-10-03T22:43:42.083Z
patrick.altair
<p>You can use <a href="https://craftcms.stackexchange.com/questions/13491/can-you-get-the-http-status-code-in-twig-templates">this</a> answer to create <a href="https://craftcms.com/docs/plugins/variables" rel="nofollow noreferrer">Template Variable</a>.
Then use it like this:</p>

<pre><code>{%- if craft.myPlugin.getHttpStatus() != 404 -%}
    {%- include "_globals/_footer" -%}
{%- endif -%}
</code></pre>

CC BY-SA 3.0
2017-03-31T16:17:53.360Z
2017-03-31T16:17:53.360Z
2017-04-13T12:51:00.303Z
Krzysztof Boduch
<p>There may be a better way, including adding exclusions as an array and checking if the segment exists in the array, but what about wrapping it in an if tag? This seems to work.</p>

<pre><code>{% if craft.request.firstSegment != 'contact' and craft.request.firstSegment != '404'  %}
    {% include 'layouts/partials/my-template'%}
{% endif %}
</code></pre>

<p><strong>Quick update:</strong> This is very rough but an example with exclusions array (doesnt account for other segments, just an example...</p>

<pre><code>{% set exclusions = ['contact','404'] %}
{% if craft.request.firstSegment not in exclusions  %}
    {% include 'layouts/partials/my-template'%}
{% endif %}
</code></pre>

CC BY-SA 3.0
2017-03-31T19:54:58.987Z
Thank you SO much! Never new about exclusions before this!
Spheriri
CC BY-SA 3.0
2017-03-31T20:06:17.850Z
It's just a twig array (you can name it anything) then the if tag just makes sure the first segment (in my example) doesn't match anything in that array. Good luck.
Shift2Design
CC BY-SA 3.0
2017-03-31T16:17:45.850Z
2017-03-31T16:23:05.943Z
2017-03-31T16:23:05.943Z
Shift2Design
<p>is there a simple way to exclude an 'include' for specific pages? </p>

<p>For instance I have an include <strong>{% include "_globals/_footer" %}</strong> but I don't want it to appear on my contact and 404 pages. 
How would I exclude it? </p>

<p>Thank you! </p>

<templating><craft-pro><craft-features><craft3>
Excluding an include template
# Excluding an include template

(Asked by: username_0 on 2017-03-31)

is there a simple way to exclude an 'include' for specific pages?

For instance I have an include **{% include "\_globals/\_footer" %}** but I don't want it to appear on my contact and 404 pages.
How would I exclude it?

Thank you!

**Tags:** templating, craft-pro, craft-features, craft3


---

## 4 answers

### Answer by username_4 on 2017-03-31. Score: 4 | Accepted answer

There may be a better way, including adding exclusions as an array and checking if the segment exists in the array, but what about wrapping it in an if tag? This seems to work.
{% if craft.request.firstSegment != 'contact' and craft.request.firstSegment != '404'  %}
    {% include 'layouts/partials/my-template'%}
{% endif %}

Quick update: This is very rough but an example with exclusions array (doesnt account for other segments, just an example...
{% set exclusions = ['contact','404'] %}
{% if craft.request.firstSegment not in exclusions  %}
    {% include 'layouts/partials/my-template'%}
{% endif %}

> **Comments:**
> **username_0**: Thank you SO much! Never new about exclusions before this!  
> **username_4**: It's just a twig array (you can name it anything) then the if tag just makes sure the first segment (in my example) doesn't match anything in that array. Good luck.  

---

### Answer by username_1 on 2017-04-06. Score: 3

Another way would be to use:
{% include [
    '_globals/footer-' ~ craft.request.lastSegment,
    '_globals/footer'
] %}

You'd then have your regular footer.twig for all pages, but you could have a footer-404.twig that would just render on the 404 page.
Note: I think the previous solutions are better, but variety of solutions is always good, right?


---

### Answer by username_2 on 2018-10-03. Score: 2

Just in case anyone stumbles across this and is using craft 3 "craft.request.firstSegment" is now deprecated in favour of "craft.app.request.segments|first". So this is now:
{# Includes the footer on all pages except homepage, contact and 404 #}
{% set exclusions = ['', 'contact', '404'] %}
{% if craft.app.request.segments|first not in exclusions  %}
    {% include '_footer'%}
{% endif %}


---

### Answer by username_3 on 2017-03-31. Score: 1

You can use this answer to create Template Variable.
Then use it like this:
{%- if craft.myPlugin.getHttpStatus() != 404 -%}
    {%- include "_globals/_footer" -%}
{%- endif -%}


---

