GRAV 子导航GRAV

2023-09-07 00:38:51 作者:思念苦无药

I try to make my first site with GRAV CMS. Now in my pages-folder it looks like this:

home/default.md about about/seite1/default.md about/seite2/default.md

Now, if i put the following code into my html-file, only the main points are showed in the navigation.

<nav class="" role="navigation">        
    <div class="">
        <ol class="">
            {% for page in pages.children %}
            {% if page.visible %}
            {% set current_page = (page.active or page.activeChild) ? 'active' : '' %}
            <li class="{{ current_page }}"><a href="{{ page.url }}">{{ page.menu }}</a</li>
            {% endif %}
            {% endfor %}                
        </ol>
    </div>
</nav>
不管车子高低配,方向盘下一插口别浪费,一插车子有劲不费油

Is there a way to show all the pages, including subpages in the navigation?

thanks for your answer...

解决方案

This should give you the fist level of children (subpages) in your navigation:

<nav class="" role="navigation">        
    <div class="">
        <ol class="">
            {% for page in pages.children %}
                {% if page.visible %}
                    {% set current_page = (page.active or page.activeChild) ? 'active' : '' %}
                    <li class="{{ current_page }}"><a href="{{ page.url }}">{{ page.menu }}</a></li>
                    {% if page.children %}
                        <ol class="">
                        {% for child in page.children %}
                            {% if child.visible %}
                                <li class="{{ current_page }}"><a href="{{ child.url }}">{{ child.menu }}</a></li>
                            {% endif %}
                        {% endfor %}
                        </ol>
                    {% endif %}
                {% endif %}
            {% endfor %}                
        </ol>
    </div>
</nav>