<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>

CC BY-SA 3.0
2014-10-21T18:47:37.683Z
One would think that `hasDescendants()` and `getDescendants()` behave the same ...
maxx
CC BY-SA 3.0
2014-10-21T18:50:23.300Z
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.
Brandon Kelly
CC BY-SA 3.0
2014-10-21T18:03:49.040Z
2014-10-21T18:03:49.040Z
Brandon Kelly
<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>

<templating><entries><structure>
Problem with entry.hasDescendants()
# 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:

**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:
{% set hasDescendants = entry.descendants.total() %}

Or in your case:


entry.descendants is an alias for EntryModel::getDescendants(), which will return a new 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.  

---

