Skip to content
Grav 2.1 is out: every page speaks Markdown. Read the announcement →

Sub navigation collection on each page

Solved by pamtbaau View solution

Started by Fre 8 years ago · 1 replies · 717 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 jeremycherfas, 1 week ago
5 196 3 hours ago
General · by lynbor, 6 days ago
2 129 3 days ago
General · by Old Man Umby, 1 week ago
1 103 1 week ago
General · by Sebastian, 2 weeks ago
1 128 2 weeks ago
General · by Andy Miller, 3 weeks ago
0 251 3 weeks ago