<p>The <a href="http://twig.sensiolabs.org/doc/templates.html#containment-operator"><strong>Containment Operator</strong></a> helps with this...</p>

<blockquote>
  <p>It returns true if the left operand is contained in the right</p>
</blockquote>

<pre><code>{% if craft.request.getSegment(2) in ['knowledge', 'search'] %}
</code></pre>

<p>OR</p>

<pre><code>{% if craft.request.getSegment(2) not in ['', 'sale'] %}
</code></pre>

CC BY-SA 3.0
2014-06-27T18:30:43.307Z
I hope you enjoyed learning from yourself. I didn't know you could do this!
Matt Stein
CC BY-SA 3.0
2014-06-27T18:33:24.587Z
When you post a question, there is an option to answer the question yourself at the bottom of the form (http://screencast.com/t/2mNCYI8og). I'm moving over my Google+ questions with answers and also posting things that I have to research/lookup so that I can find them again quickly & make the answer available to others.
Anna_MediaGirl
CC BY-SA 3.0
2014-06-27T18:34:48.663Z
I know, I'm just being "funny." Self-answers still amuse me even when they're mine, but this was a cool thing to learn.
Matt Stein
CC BY-SA 3.0
2014-06-27T18:36:08.517Z
I'm doing my part! My questions are going to be all Twig related probably since that's where I'm working most.
Anna_MediaGirl
CC BY-SA 3.0
2014-06-27T18:21:54.197Z
2014-06-27T18:38:04.673Z
2014-06-27T18:38:04.673Z
Anna_MediaGirl
<p>Is there a way in Twig to make this conditional shorter so I don't use "craft.request.getSegment(2)" twice?</p>

<pre><code>{% if craft.request.getSegment(2) == "knowledge" or 
craft.request.getSegment(2) == "search" %}
</code></pre>

<conditional>
Is Shorter Twig Conditional possible?
# Is Shorter Twig Conditional possible?

(Asked by: username_0 on 2014-06-27)

Is there a way in Twig to make this conditional shorter so I don't use "craft.request.getSegment(2)" twice?
{% if craft.request.getSegment(2) == "knowledge" or 
craft.request.getSegment(2) == "search" %}

**Tags:** conditional


---

## 1 answers

### Answer by username_0 on 2014-06-27. Score: 11 | Accepted answer

The Containment Operator helps with this...

It returns true if the left operand is contained in the right

{% if craft.request.getSegment(2) in ['knowledge', 'search'] %}

OR
{% if craft.request.getSegment(2) not in ['', 'sale'] %}

> **Comments:**
> **username_1**: I hope you enjoyed learning from yourself. I didn't know you could do this!  
> **username_0**: When you post a question, there is an option to answer the question yourself at the bottom of the form (http://screencast.com/t/2mNCYI8og). I'm moving over my Google+ questions with answers and also posting things that I have to research/lookup so that I can find them again quickly & make the answer available to others.  
> **username_1**: I know, I'm just being "funny." Self-answers still amuse me even when they're mine, but this was a cool thing to learn.  
> **username_0**: I'm doing my part! My questions are going to be all Twig related probably since that's where I'm working most.  

---

