Skip to content
● Grav 2.2 is out: 2x faster cold starts and 96% less memory on big sites. Read the announcement →

Sub navigation collection on each page

Solved by pamtbaau View solution

Started by Fre 8 years ago · 1 replies · 742 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 Andy Miller, 7 days ago
0 117 7 days ago
General · by lynbor, 1 month ago
3 445 2 weeks ago
General · by lynbor, 3 weeks ago
7 564 2 weeks ago
General · by Harry, 2 weeks ago
0 165 2 weeks ago
General · by Old Man Umby, 1 month ago
2 310 4 weeks ago