Answers.Body: <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>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-06-27T18:30:43.307Z
Answers.Text: I hope you enjoyed learning from yourself. I didn't know you could do this!
Answers.UserDisplayName: Matt Stein
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-06-27T18:33:24.587Z
Answers.Text: 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.
Answers.UserDisplayName: Anna_MediaGirl
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-06-27T18:34:48.663Z
Answers.Text: 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.
Answers.UserDisplayName: Matt Stein
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-06-27T18:36:08.517Z
Answers.Text: I'm doing my part! My questions are going to be all Twig related probably since that's where I'm working most.
Answers.UserDisplayName: Anna_MediaGirl
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-06-27T18:21:54.197Z
Answers.LastActivityDate: 2014-06-27T18:38:04.673Z
Answers.LastEditDate: 2014-06-27T18:38:04.673Z
Answers.UserDisplayName: Anna_MediaGirl
Body: <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>
  
Tags: <conditional>
Title: Is Shorter Twig Conditional possible?
ThreadText: # 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**](http://twig.sensiolabs.org/doc/templates.html#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.  
  
  ---
  
  