Answers.Body: <p>hasDescendants() is only concerned with whether the entry actually has descendants; not whether they are enabled or not.</p>
  
  <p>To determine in an entry has <em>enabled</em> descendants, you can do this:</p>
  
  <pre class="lang-twig prettyprint-override"><code>{% set hasDescendants = entry.descendants.total() %}
  </code></pre>
  
  <p>Or in your case:</p>
  
  <pre class="lang-twig prettyprint-override"><code>&lt;li class="{% if nav_item.descendants.total() %}more{% endif %}"&gt;
  </code></pre>
  
  <p><code>entry.descendants</code> is an alias for <a href="http://buildwithcraft.com/docs/templating/entrymodel#getDescendants" rel="nofollow">EntryModel::getDescendants()</a>, which will return a new <a href="http://buildwithcraft.com/docs/templating/elementcriteriamodel" rel="nofollow">ElementCriteriaModel</a> prepped to return descendants of <code>entry</code>. By default it will only return the enabled ones, like all ElementCriteriaModel’s.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-10-21T18:47:37.683Z
Answers.Text: One would think that `hasDescendants()` and `getDescendants()` behave the same ...
Answers.UserDisplayName: maxx
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-10-21T18:50:23.300Z
Answers.Text: They serve different needs. `hasDescendants` will just return a binary `true` or `false` depending on whether the entry has any descendants, without any support for parameters that could affect the answer. `getDescendants()` will actually trigger a DB query, so it can afford to accept parameters, and offer the data in different formats, depending on your needs.
Answers.UserDisplayName: Brandon Kelly
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-10-21T18:03:49.040Z
Answers.LastActivityDate: 2014-10-21T18:03:49.040Z
Answers.UserDisplayName: Brandon Kelly
Body: <p>So I have a Structure like that</p>
  
  <ul>
  <li>Item
  <ul>
  <li>Subitem | inactive</li>
  <li>Subitem | inactive</li>
  </ul></li>
  </ul>
  
  <p>why is <code>item.hasDescendants()</code> true ?</p>
  
  <p>How would I do something like that the right way:</p>
  
  <pre><code>&lt;li class="{% if nav_item.hasDescendants() %}more{% endif %}"&gt;
  </code></pre>
  
Tags: <templating><entries><structure>
Title: Problem with entry.hasDescendants()
ThreadText: # Problem with entry.hasDescendants()
  
  (Asked by: username_0 on 2014-10-05)
  
  So I have a Structure like that
  
  * Item
    + Subitem | inactive
    + Subitem | inactive
  
  why is `item.hasDescendants()` true ?
  
  How would I do something like that the right way:
  
  ```
  <li class="{% if nav_item.hasDescendants() %}more{% endif %}">
  
  ```
  
  **Tags:** templating, entries, structure
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2014-10-21. Score: 2
  
  hasDescendants() is only concerned with whether the entry actually has descendants; not whether they are enabled or not.
  
  To determine in an entry has *enabled* descendants, you can do this:
  
  ```twig
  {% set hasDescendants = entry.descendants.total() %}
  
  ```
  
  Or in your case:
  
  ```twig
  <li class="{% if nav_item.descendants.total() %}more{% endif %}">
  
  ```
  
  `entry.descendants` is an alias for [EntryModel::getDescendants()](http://buildwithcraft.com/docs/templating/entrymodel#getDescendants), which will return a new [ElementCriteriaModel](http://buildwithcraft.com/docs/templating/elementcriteriamodel) prepped to return descendants of `entry`. By default it will only return the enabled ones, like all ElementCriteriaModel’s.
  
  > **Comments:**
  > **username_0**: One would think that `hasDescendants()` and `getDescendants()` behave the same ...  
  > **username_1**: They serve different needs. `hasDescendants` will just return a binary `true` or `false` depending on whether the entry has any descendants, without any support for parameters that could affect the answer. `getDescendants()` will actually trigger a DB query, so it can afford to accept parameters, and offer the data in different formats, depending on your needs.  
  
  ---
  
  