Answers.Body: <p>Instead of using <code>{% ifchildren %}</code> use <code>{% if entry.hasDescendants %}</code>. It allows for more flexibility in your nav templating.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-07-30T15:48:42.617Z
Answers.LastActivityDate: 2019-07-30T15:48:42.617Z
Answers.UserDisplayName: Simon Kuran
Body: <p>I want to change the URL of a li from a nav menu conditionally (using a custom field where the user sets the URL), but I don't see how to use conditionals with <code>{% ifchildren %}</code>?</p>
  
  <pre><code>{% nav entry in entries %}
      &lt;li&gt;
          &lt;a href="{{ entry.url }}"&gt;{{ entry.title }}&lt;/a&gt;
  
          {% if entry.id in craft.entries.descendantOf(4).ids() %}
              **change the url of all child entries**
          {% endif %}
  
          {% ifchildren %}
              &lt;ul class="menu sub-items"&gt;
                  {% children %}
              &lt;/ul&gt;
          {% endifchildren %}
      &lt;/li&gt;
  {% endnav %}
  </code></pre>
  
  <p>ID 4's children is the entry which I want to display custom URLs.</p>
  
Tags: <structure><navigation><children>
Title: Change the URL of nav child entry conditionally
ThreadText: # Change the URL of nav child entry conditionally
  
  (Asked by: username_0 on 2019-07-30)
  
  I want to change the URL of a li from a nav menu conditionally (using a custom field where the user sets the URL), but I don't see how to use conditionals with `{% ifchildren %}`?
  
  ```
  {% nav entry in entries %}
      <li>
          <a href="{{ entry.url }}">{{ entry.title }}</a>
  
          {% if entry.id in craft.entries.descendantOf(4).ids() %}
              **change the url of all child entries**
          {% endif %}
  
          {% ifchildren %}
              <ul class="menu sub-items">
                  {% children %}
              </ul>
          {% endifchildren %}
      </li>
  {% endnav %}
  
  ```
  
  ID 4's children is the entry which I want to display custom URLs.
  
  **Tags:** structure, navigation, children
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2019-07-30. Score: 1 | Accepted answer
  
  Instead of using `{% ifchildren %}` use `{% if entry.hasDescendants %}`. It allows for more flexibility in your nav templating.
  
  
  ---
  
  