Show only children relative to current page I have this structure section:

1.0 Nav point level 1
  1.1 Nav point level 2
  1.2 Nav point level 2
  1.3 Nav point level 2
2.0 Nav Point level 1
3.0 Nav Point level 1


I want to show only top level points as long as there is no children ont the current page.

Example:

When im on page 1.0 Nav point level 1 the navi shoud look like above (Because the current page has descendants).

But when im on 2.0 Nav Point level 1 the navi should look like this:
(Everything below level 1 not visible because the current page has no children.)

1.0 Nav point level 1
2.0 Nav Point level 1
3.0 Nav Point level 1


I tried to wrap the children tag into a conditional. But that's not allowed:

{% set topLevel = (entry.level == 1) ? entry : entry.getAncestors().level(1).first()  %}


{% if topLevel.hasDescendants %}

  &lt;nav class="subNav"&gt;

    &lt;ul&gt;

      {% set subnav =  topLevel.getDescendants()  %}

      {% nav page in subnav  %}
        &lt;li&gt;
            &lt;a href="{{ page.url }}"&gt;{{ page.title }}&lt;/a&gt;
            {% if entry.hasDescendantes %} // this does not work at all.
              {% ifchildren %}
                &lt;ul&gt;{% children %}&lt;/ul&gt;
              {% endifchildren %}
            {% endif %}
        &lt;/li&gt;
      {% endnav %}

    &lt;/ul&gt;

  &lt;/nav&gt;
{% endif %}


I can't wrap my head around it.
Don't use the nav tag. Assuming a structure called pages, try something like this:

{% set pages = craft.entries.section('pages').level(1).all() %}
&lt;ul&gt;
{% for page in pages %}
    &lt;li&gt;
        {{ page.title }}
        {% if entry is defined and entry.hasDescendants %}
            {% set children = page.getChildren() %}
            &lt;ul&gt;
            {% for child in children %}
                &lt;li&gt;{{ child.title }}&lt;/li&gt;
            {% endfor %}
            &lt;/ul&gt;
        {% endif %}
    &lt;/li&gt;
{% endfor %}
&lt;/ul&gt;