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

Sub navigation collection on each page

Solved by pamtbaau View solution

Started by Fre 8 years ago · 1 replies · 589 views
8 years ago

I've added a subnavigation in the footer of a webpage which are the children of page info. The issue I have is that every time I need to add the collection to the page I create in the admin module like this (so on every .md file I want to have the submenu available:)
infomenu:
items:

TXT
        '@page.children': /info

This is my subnav.twig file:

<div class="subnav">/
{% for p in page.collection('infomenu') %}
{% set active_page = (p.active or p.activeChild) ? 'active' : '' %}
<a href="{{ p.url }}" class="{{ active_page }}">{{ p.menu }}</a> /
{% endfor %}
</div>

It would be nice if the collection could be defined in the blueprint, however this is not working. Is there a way so that a collection is available on every page?

thnx

8 years ago Solution

@freeyland You could define a twig template and define the collection inside the template. Have a look at the docs on Collection Object Methods for an example of a collection created in Twig.

Then {% include %} the template inside the footer section of 'base.html.twig'. Now every page will have the navigation inside the footer.

Suggested topics

Topic Participants Replies Views Activity
General · by Hanns Mattes, 19 hours ago
1 26 12 hours ago
General · by Andy Miller, 12 hours ago
0 25 12 hours ago
General · by Jerry Hunt, 5 days ago
2 145 2 days ago
General · by pamtbaau, 2 days ago
1 96 2 days ago
General · by Andy Miller, 2 days ago
0 80 2 days ago