Skip to content
Grav 2.0 is officially stable. Read the announcement →
Archive

Modular submenu

Started by Muut Archive 10 years ago · 8 replies · 1829 views
10 years ago

is it possible to create submenu from modular pages? Got side navigation like Services > One collection of services > list of additional infos , and am unable to display it

10 years ago

my subnav code:

{% set collection = page.find('/zakroky').collection %}

<ul class="navigation">
{% for page in collection %}

TWIG
    {% if page.visible %}
        {% set activepage = (page.active) ? 'active' : '' %}
        <li><a class="{{ activepage }}" href="{{ page.url }}">{{ page.menu }}</a>
                {% if page.children %}
                    <ol class="">
                    {% for child in page.children %}
                        {% if child.visible %}
                            <li><a href="{{ child.url }}">{{ child.title }}</a</li>
                        {% endif %}
                    {% endfor %}
                    </ol>
                {% endif %}
        </li> 
    {% endif %}
{% endfor %}

</ul>

10 years ago

yeah, sorry for that / but problem is, ive got

TWIG
{% set collection = page.find('/services').children %}

and my services folder is modular listing of separate services and one of them is also modular part of it …pretty crazy stuff … hm..?
so i can only achieve listing of ALL topics, or none of them =[

10 years ago

{% set collection = page.find('/services').children %}

<ul class="navigation">
{% for page in collection %}

TWIG
        {% set activepage = (page.active) ? 'active' : '' %}
        <li><a class="{{ activepage }}" href="{{ page.url }}">{{ page.title }}</a>
        <!-- here i would like to have my submenu =] -->
        </li>
{% endfor %}

</ul>

10 years ago
TWIG

{% set collection = page.find('/services').collection %}

<ul class="navigation">
    {% for page in collection %}

        {% if page.visible %}
            {% set activepage = (page.active) ? 'active' : '' %}
            <li><a class="{{ activepage }}" href="{{ page.url }}">{{ page.title }}</a>
            {% if page.find('/services/first-services-which-have-another-modules-inside' ).children %}
                show sub menu test
            {% endif %}
            </li>
        {% endif %}
    {% endfor %}
</ul>
---
10 years ago

This macro in Antimatter loops through all the pages and even goes into the children in order to build a dropdown-capable menu.

https://github.com/getgrav/grav-theme-antimatter/blob/develop/templates/partials/navigation.html.twig#L1-L16

You will notice it is checking for visible pages, and as modular pages are not visible (ie don't show up in a menu) it will filter them out. You could remove that, but then the problem is they are not routable so you can't have a URL to them directly. You would need to manually create a URL with an anchor or something to jump to part of the page. Then on the page itself you would have to the template output the appropriate anchor link tag.

10 years ago

but what if i want to check the structure from 2nd or certain level ...not from root?

10 years ago

You could have a special if check for a particular parent page so you perform your modular logic only on pages you choose.

Suggested topics

Topic Participants Replies Views Activity
Archive · by Deleted User, 9 years ago
0 1354 9 years ago
Archive · by Muut Archive, 9 years ago
2 935 9 years ago
Archive · by Muut Archive, 9 years ago
2 4065 9 years ago
Archive · by Muut Archive, 9 years ago
1 2953 9 years ago
Archive · by Muut Archive, 9 years ago
3 1119 9 years ago