Answers.Body: <p>In Twig you'll never, ever need to nest <a href="http://buildwithcraft.com/docs/twig-primer#logic-tags" rel="nofollow">logic tags</a>, within <a href="http://buildwithcraft.com/docs/twig-primer#output-tags" rel="nofollow">output tags</a> or visa-versa.</p>
  
  <p>The syntax you're looking for is:</p>
  
  <pre><code>{% set about_entry = craft.entries.id(17).first() %}
  
  &lt;ul&gt;
      &lt;li {% if craft.request.getSegment(1) == about_entry.uri %}class="here"{% endif %}&gt;&lt;a href="{{ about_entry.url }}"&gt;{{ about_entry.title }}&lt;/a&gt;&lt;/li&gt;
  &lt;/ul&gt;
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-01-19T03:56:04.343Z
Answers.LastActivityDate: 2015-01-19T05:46:27.790Z
Answers.LastEditDate: 2015-01-19T05:46:27.790Z
Answers.UserDisplayName: Brad Bell
Body: <p>I'm trying to write a conditional that adds a class of 'here' to a navigation menu item if segment_1 of the URL matches the URI of the entry I'm specifying. But it isn't outputting anything, so I'd appreciate any help with this, thanks. Here's my code:</p>
  
  <pre><code>{% set about_entry = craft.entries.id(17).first() %}
  
  &lt;ul&gt;
    &lt;li {% if craft.request.getSegment(1) == '{{ about_entry.uri }}' %}class="here"{% endif %}&gt;&lt;a href="{{ about_entry.url }}"&gt;{{ about_entry.title }}&lt;/a&gt;&lt;/li&gt;
  &lt;/ul&gt;
  </code></pre>
  
  <p>This conditional works fine if I change '{{ about_entry.uri }}' for a hard-coded 'about', but I want the URI to be dynamic in case it gets changed in the future/</p>
  
Tags: <templating><navigation><conditional>
Title: Conditional to compare segment_1 in the URL with the URI of a specified entry
ThreadText: # Conditional to compare segment_1 in the URL with the URI of a specified entry
  
  (Asked by: username_0 on 2015-01-19)
  
  I'm trying to write a conditional that adds a class of 'here' to a navigation menu item if segment\_1 of the URL matches the URI of the entry I'm specifying. But it isn't outputting anything, so I'd appreciate any help with this, thanks. Here's my code:
  
  ```
  {% set about_entry = craft.entries.id(17).first() %}
  
  <ul>
    <li {% if craft.request.getSegment(1) == '{{ about_entry.uri }}' %}class="here"{% endif %}><a href="{{ about_entry.url }}">{{ about_entry.title }}</a></li>
  </ul>
  
  ```
  
  This conditional works fine if I change '{{ about\_entry.uri }}' for a hard-coded 'about', but I want the URI to be dynamic in case it gets changed in the future/
  
  **Tags:** templating, navigation, conditional
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2015-01-19. Score: 2 | Accepted answer
  
  In Twig you'll never, ever need to nest [logic tags](http://buildwithcraft.com/docs/twig-primer#logic-tags), within [output tags](http://buildwithcraft.com/docs/twig-primer#output-tags) or visa-versa.
  
  The syntax you're looking for is:
  
  ```
  {% set about_entry = craft.entries.id(17).first() %}
  
  <ul>
      <li {% if craft.request.getSegment(1) == about_entry.uri %}class="here"{% endif %}><a href="{{ about_entry.url }}">{{ about_entry.title }}</a></li>
  </ul>
  
  ```
  
  
  ---
  
  