<p>Is there a chance that you're getting the another entry with the the same slug as your <code>mainEntry</code>? I'd try to further filter it down by adding <a href="http://buildwithcraft.com/docs/templating/craft.entries#section" rel="nofollow"><code>section()</code></a> for example.</p>

<p>As I wrote in the comments, try to loosen the second ElementCriteriaModel by removing the <a href="http://buildwithcraft.com/docs/templating/craft.entries#level" rel="nofollow"><code>level</code></a> parameter.</p>

<p>Another idea would be to use the <a href="http://twig.sensiolabs.org/doc/functions/dump.html" rel="nofollow"><code>dump()</code></a> function on your <code>mainEntry</code> (only works with dev-mode turned on).</p>

CC BY-SA 3.0
2014-08-15T09:46:30.413Z
Cheers - adding section() resolved the issue - must have been another slug affecting it.
mmc501
CC BY-SA 3.0
2014-08-15T07:04:45.223Z
2014-08-15T07:04:45.223Z
carlcs
<p>I'm trying to set up a sub nav from a Structure Section on my site.</p>

<p>Current code is:</p>

<pre><code>{% set mainEntry = craft.entries.slug(craft.request.getSegment(1)).first() %}
{% set subnav = craft.entries.descendantOf(mainEntry).level(2) %}

{{ subnav.total() }}
</code></pre>

<p>But my when loop through sub nav below it returns nothing.
I am outputting subnav.total above but it is returning 0, but there is a lot of entries  in the CMS.</p>

<p>mainEntry gets loaded with the correct info ok, but I don't get anything in subnav. </p>

CC BY-SA 3.0
2014-08-14T18:08:40.190Z
Your code look right to me, mmc. What happens if you remove `.level(2)`? Are you not getting descendants at all?
carlcs
CC BY-SA 3.0
2014-08-15T05:48:03.713Z
No I'm getting nothing at all - when I remove .level(2) {{ subnav.total() }} still output's 0
mmc501
<entries><navigation><structure>
Structure Navigation - Not returning sub nav entries
# Structure Navigation - Not returning sub nav entries

(Asked by: username_0 on 2014-08-14)

I'm trying to set up a sub nav from a Structure Section on my site.
Current code is:
{% set mainEntry = craft.entries.slug(craft.request.getSegment(1)).first() %}
{% set subnav = craft.entries.descendantOf(mainEntry).level(2) %}

{{ subnav.total() }}

But my when loop through sub nav below it returns nothing.
I am outputting subnav.total above but it is returning 0, but there is a lot of entries  in the CMS.
mainEntry gets loaded with the correct info ok, but I don't get anything in subnav.

**Tags:** entries, navigation, structure

> **Comments:**
> **username_1**: Your code look right to me, mmc. What happens if you remove `.level(2)`? Are you not getting descendants at all?  
> **username_0**: No I'm getting nothing at all - when I remove .level(2) {{ subnav.total() }} still output's 0  

---

## 1 answers

### Answer by username_1 on 2014-08-15. Score: 1 | Accepted answer

Is there a chance that you're getting the another entry with the the same slug as your `mainEntry`? I'd try to further filter it down by adding [`section()`](http://buildwithcraft.com/docs/templating/craft.entries#section) for example.

As I wrote in the comments, try to loosen the second ElementCriteriaModel by removing the [`level`](http://buildwithcraft.com/docs/templating/craft.entries#level) parameter.

Another idea would be to use the [`dump()`](http://twig.sensiolabs.org/doc/functions/dump.html) function on your `mainEntry` (only works with dev-mode turned on).

> **Comments:**
> **username_0**: Cheers - adding section() resolved the issue - must have been another slug affecting it.  

---

