GRAV subnavigation

[亡魂溺海] 提交于 2019-12-07 07:11:31

问题


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


回答1:


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>


来源:https://stackoverflow.com/questions/25423375/grav-subnavigation

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!