<p>You should be able to utilize twig's built-in containment operator.</p>

<p>Your code would look like this:</p>

<pre><code>{% if 'vascular' in craft.request.getSegment(3) %}
    ...
{% endif %}
</code></pre>

<p>Here is official documentation on the containment operator: <a href="http://twig.sensiolabs.org/doc/templates.html#containment-operator" rel="nofollow">http://twig.sensiolabs.org/doc/templates.html#containment-operator</a>.</p>

CC BY-SA 3.0
2016-09-23T20:35:07.213Z
2016-09-23T20:35:07.213Z
Greg
<p>Is there a way to partially match text in a URL segment? I would like to conditionally show code if the text "vascular" is in Segment 3.</p>

<p>If my URL is: <code>https://website.com/segment1/segment2/10009-vascular-access</code></p>

<p>This is what I've tried so far...</p>

<pre><code>{% if craft.request.getSegment(3) == 'vascular' %}

{% if craft.request.getSegment(3).contains("vascular") %}
</code></pre>

<url><getsegment>
Partial match in URL getSegment()
# Partial match in URL getSegment()

(Asked by: username_0 on 2016-09-23)

Is there a way to partially match text in a URL segment? I would like to conditionally show code if the text "vascular" is in Segment 3.
If my URL is: https://website.com/segment1/segment2/10009-vascular-access
This is what I've tried so far...
{% if craft.request.getSegment(3) == 'vascular' %}

{% if craft.request.getSegment(3).contains("vascular") %}

**Tags:** url, getsegment


---

## 1 answers

### Answer by username_1 on 2016-09-23. Score: 2 | Accepted answer

You should be able to utilize twig's built-in containment operator.
Your code would look like this:
{% if 'vascular' in craft.request.getSegment(3) %}
    ...
{% endif %}

Here is official documentation on the containment operator: http://twig.sensiolabs.org/doc/templates.html#containment-operator.


---

