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

Separate sub navbar

Started by Muut Archive 11 years ago · 5 replies · 307 views
11 years ago

How can I build up a list of sub links to the current page?

11 years ago

Maybe your looking for what we would term as a split-menu ? By that I mean that rather than showing the dropdown menus for all pages all the time (like a traditional dropdown menu does), it only shows the children of the current page.

This could be done by simply iterating over the current page's children if it has any. Something like (untested) :

TWIG
{% if page.children %}
<h3>SubMenu</h3>
<ul id="split-menu">
  {% for child in page.children %}
    <li>
      <a href="{{ child.url }}">{{ child.menu }}</a>
    </li>
  {% endfor %}
</ul>
{% endif %}
👍 1
11 years ago

Trying to adapt this code to my own site, and your code does work well. However I would like to modify it to include some more detail for each menu item. Is there anywhere I can see what each child contains? (No formal programming quals so I don't know the apt terminology here)

For example, child.url is the url, child.menu seems to be the title of the page, I've found out that child.name is the actual filename. What else is there, and how can I find it out?

What I would like is to be able to use the taxonomy of each child to build the list. However using child.taxonomy() or child.taxonomy(category) returns an array (I'm guessing) which throws up an exception when loading the page.

11 years ago

Just add some custom header variables in each page mycustom1: foo

and then access them in the twig with {{ child.header.mycustom1 }}

Suggested topics

Topic Participants Replies Views Activity
Archive · by Deleted User, 9 years ago
0 1336 9 years ago
Archive · by Muut Archive, 9 years ago
2 925 9 years ago
Archive · by Muut Archive, 9 years ago
2 4056 9 years ago
Archive · by Muut Archive, 9 years ago
1 2941 9 years ago
Archive · by Muut Archive, 9 years ago
3 1112 9 years ago