<p>You could use either <code> | last</code> filter instead of first or, a combination of first and another conditional ( segments[1] is empty or similar)?</p>
<pre><code>{% set segments = craft.app.request.segments %}
{% if segments | first == “projects” and segments[1] is empty %}
Load scripts
{% endif %}
</code></pre>
<p>On phone so ymmv</p>

CC BY-SA 4.0
2020-07-04T00:22:12.103Z
You might also be able to just test craft.app.request.uri or something (path?) check the request docs?
billythekid
CC BY-SA 4.0
2020-07-04T00:20:48.280Z
2020-07-04T00:20:48.280Z
billythekid
<p>You might check if <code>projects</code> is part of URL:</p>
<pre><code>{% if 'projects' in craft.app.request.segments|split('/') %}
Load scripts
{% endif %}
</code></pre>

CC BY-SA 4.0
2020-07-04T07:47:40.097Z
2020-07-04T07:47:40.097Z
Piotr Pogorzelski
<p>I'd like to only load some scripts for 1 specific page with the Url <code>/projects/</code>.</p>
<p>Currently I'm using:</p>
<pre><code>{% if craft.app.request.segments|first == 'projects' %}
 // load scripts
{% endif %}
</code></pre>
<p>This works.</p>
<p>However, I also have pages with the Url <code>/projects/project-name</code> which should not load the script.</p>
<p>How can you perform a conditional test for just the Url <code>/projects/</code> ?</p>
<p>Thanks</p>

CC BY-SA 4.0
2020-07-04T07:58:27.283Z
`{% if craft.app.request.segments|last == 'projects' %}` did the trick
David Flindall
<url><conditional>
Conditional for specific page
# Conditional for specific page

(Asked by: username_0 on 2020-07-03)

I'd like to only load some scripts for 1 specific page with the Url /projects/.
Currently I'm using:
{% if craft.app.request.segments|first == 'projects' %}
 // load scripts
{% endif %}

This works.
However, I also have pages with the Url /projects/project-name which should not load the script.
How can you perform a conditional test for just the Url /projects/ ?
Thanks

**Tags:** url, conditional
> **Comments:**
> **username_0**: `{% if craft.app.request.segments|last == 'projects' %}` did the trick  

---

## 2 answers

### Answer by username_1 on 2020-07-04. Score: 2 | Accepted answer

You could use either  | last filter instead of first or, a combination of first and another conditional ( segments[1] is empty or similar)?
{% set segments = craft.app.request.segments %}
{% if segments | first == “projects” and segments[1] is empty %}
Load scripts
{% endif %}

On phone so ymmv

> **Comments:**
> **username_1**: You might also be able to just test craft.app.request.uri or something (path?) check the request docs?  

---

### Answer by username_2 on 2020-07-04. Score: 1

You might check if projects is part of URL:
{% if 'projects' in craft.app.request.segments|split('/') %}
Load scripts
{% endif %}


---

