Answers.Body: <p>Try using:</p>
  
  <pre><code>   {% set pageIsActive = (page.id == entry.id) %}
  </code></pre>
  
  <p>and then testing for that in your if statements.</p>
  
  <p><a href="http://craftcookbook.net/recipes/388" rel="nofollow">This article</a> covers pretty much every eventuality when it comes to classes and navigation and should help you achieve the markup you are after.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-08-13T14:21:34.890Z
Answers.LastActivityDate: 2015-08-13T14:28:41.780Z
Answers.LastEditDate: 2015-08-13T14:28:41.780Z
Answers.UserDisplayName: j00lz
Body: <p>Currently we're highlighting the active page in our navigation by having a structure of menu items with a "menuLink" field and comparing that to the current entry uri. Something like this:</p>
  
  <pre><code>{% nav link in Menu %}
      &lt;li&gt;
          {% if link.menuLink|length %}
              &lt;a{% if link.slug == entry.uri %} class="active"{% endif %} href="{{ link.menuLink[0].url }}"&gt;{{ link.title }}&lt;/a&gt;
          {% else %}
              &lt;a href="{{ link.customUrl }}"&gt;{{ link.title }}&lt;/a&gt;
          {% endif %}
      &lt;/li&gt; 
  {% endnav %}
  </code></pre>
  
  <p>However, this doesn't work for children of structures or channels. We could change the if statement to look for the entry.uri OR the entry.section as below but obviously that only works if the section/channel has the same name as the link.slug:</p>
  
  <pre><code>{% if link.slug == entry.uri or link.slug == entry.section %} class="active"{% endif %}
  </code></pre>
  
  <p>I searched through the previous questions but all the answers to this problem seem to involve reading a section of the URL but we want to be able to control the URLs and have some structure children have a top level URL rather than a /structure-name/{slug}</p>
  
  <p>If we could have a field on the structure itself to say which menu item to highlight then you could just say something like </p>
  
  <pre><code>if entry.section.type == channel or structure then active menu item = entry.section.menuItem 
  </code></pre>
  
  <p>but you can't have a field on a structure/channel as far as I'm aware?</p>
  
  <p>Does anyone know of a way of solving this problem without the use of URL segments?</p>
  
Tags: <structure><navigation><channels>
Title: Set navigation menu item to active for child pages
ThreadText: # Set navigation menu item to active for child pages
  
  (Asked by: username_0 on 2015-08-13)
  
  Currently we're highlighting the active page in our navigation by having a structure of menu items with a "menuLink" field and comparing that to the current entry uri. Something like this:
  
  ```
  {% nav link in Menu %}
      <li>
          {% if link.menuLink|length %}
              <a{% if link.slug == entry.uri %} class="active"{% endif %} href="{{ link.menuLink[0].url }}">{{ link.title }}</a>
          {% else %}
              <a href="{{ link.customUrl }}">{{ link.title }}</a>
          {% endif %}
      </li> 
  {% endnav %}
  
  ```
  
  However, this doesn't work for children of structures or channels. We could change the if statement to look for the entry.uri OR the entry.section as below but obviously that only works if the section/channel has the same name as the link.slug:
  
  ```
  {% if link.slug == entry.uri or link.slug == entry.section %} class="active"{% endif %}
  
  ```
  
  I searched through the previous questions but all the answers to this problem seem to involve reading a section of the URL but we want to be able to control the URLs and have some structure children have a top level URL rather than a /structure-name/{slug}
  
  If we could have a field on the structure itself to say which menu item to highlight then you could just say something like
  
  ```
  if entry.section.type == channel or structure then active menu item = entry.section.menuItem 
  
  ```
  
  but you can't have a field on a structure/channel as far as I'm aware?
  
  Does anyone know of a way of solving this problem without the use of URL segments?
  
  **Tags:** structure, navigation, channels
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2015-08-13. Score: 1
  
  Try using:
  
  ```
     {% set pageIsActive = (page.id == entry.id) %}
  
  ```
  
  and then testing for that in your if statements.
  
  [This article](http://craftcookbook.net/recipes/388) covers pretty much every eventuality when it comes to classes and navigation and should help you achieve the markup you are after.
  
  
  ---
  
  