Structure Navigation - Not returning sub nav entries 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.
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() for example.

As I wrote in the comments, try to loosen the second ElementCriteriaModel by removing the level parameter.

Another idea would be to use the dump() function on your mainEntry (only works with dev-mode turned on).