Answers.Body: <p>Have you tried something like:</p>
  
  <pre><code>&lt;li class="{{ page.getChildren()|length == 0 ? 'dropdown-item' : 'dropdown-submenu' }}"&gt;
  </code></pre>
  
  <p>If that doesn't work, I suspect you could use {% ifchildren %} in concert with a variable to set the style. In this case, we set the variable to a non-null value if there are children. Then we can use the null-coalescing operator to substitute 'dropdown-item' if there are no children. Like:</p>
  
  <pre><code>{% set listclass = null %}
  {% ifchildren %}
      {% set listclass = 'dropdown-submenu' %}
  {% endifchildren% }
  &lt;li class="{{ listclass ?? 'dropdown-item' }}"&gt;
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2018-04-26T21:35:40.543Z
Answers.Text: First one did the trick.  Thanks so much!
Answers.UserDisplayName: fodney
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2018-04-26T21:14:26.873Z
Answers.LastActivityDate: 2018-04-26T21:14:26.873Z
Answers.UserDisplayName: Nik Shenoy
Body: <p>On the menu below I need to change the class on the li from dropdown-submenu to dropdown-item for those entries that don't have children.  Any ideas?</p>
  
  <p>Thanks</p>
  
  <pre><code>{% set pages = craft.entries.section('services') %}
                         {% nav page in pages %}
             &lt;li class="dropdown-submenu"&gt; 
                  {{ page.getLink() }}
  
                  {% ifchildren %}
                     &lt;ul class="dropdown-menu" aria-labelledby="dropdownMenuLink"&gt;
                          {% children %}
                      &lt;/ul&gt;
                  {% endifchildren %}
              &lt;/li&gt;
  
          {% endnav %}
  </code></pre>
  
Tags: <navigation>
Title: Conditional statement for nav tag when no children
ThreadText: # Conditional statement for nav tag when no children
  
  (Asked by: username_0 on 2018-04-26)
  
  On the menu below I need to change the class on the li from dropdown-submenu to dropdown-item for those entries that don't have children. Any ideas?
  
  Thanks
  
  ```
  {% set pages = craft.entries.section('services') %}
                         {% nav page in pages %}
             <li class="dropdown-submenu"> 
                  {{ page.getLink() }}
  
                  {% ifchildren %}
                     <ul class="dropdown-menu" aria-labelledby="dropdownMenuLink">
                          {% children %}
                      </ul>
                  {% endifchildren %}
              </li>
  
          {% endnav %}
  
  ```
  
  **Tags:** navigation
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2018-04-26. Score: 0 | Accepted answer
  
  Have you tried something like:
  
  ```
  <li class="{{ page.getChildren()|length == 0 ? 'dropdown-item' : 'dropdown-submenu' }}">
  
  ```
  
  If that doesn't work, I suspect you could use {% ifchildren %} in concert with a variable to set the style. In this case, we set the variable to a non-null value if there are children. Then we can use the null-coalescing operator to substitute 'dropdown-item' if there are no children. Like:
  
  ```
  {% set listclass = null %}
  {% ifchildren %}
      {% set listclass = 'dropdown-submenu' %}
  {% endifchildren% }
  <li class="{{ listclass ?? 'dropdown-item' }}">
  
  ```
  
  > **Comments:**
  > **username_0**: First one did the trick.  Thanks so much!  
  
  ---
  
  