Parent menu item list parents


#1

This cant be this hard. All I want to do is have it so that a main menu item is clicked on it give a list of the child pages. Ive done this in a few other CMS. In fact here is my current one, but I want to move from Joomla/mySQL to flat Grav. Here it is in Joomla My current Joomla

Ive seen several code snippets in here to make this happen, but none of them worked or made enough sense to me to figure it out.
Thanks.


#2

@smegnl It sounds like you are looking for collections: A collection of pages having some commonality.

The documentation has a dedicated section on collections: https://learn.getgrav.org/content/collections.

A collection of ‘children’ might for example be defined in a ‘parent’ page:

---
title: Figured it Out
slug: figured-it-out
content:
    items: '@self.children'   <-- Give me a collection of all pages in my sub-folders
    order:
        by: date
        dir: desc
    limit: 10                 <-- Don't give me the whole list, but sets of 10 with pagination
    pagination: true

---
#Figured it Out
Click on a topic....

In your page’s Twig template you can then create a list as follows:

<ul>
{% for page in page.collection %}
   <li><a href="{{ page.url }}">{{ page.title }}</a></li>
{% endfor %}
</ul>

Hope this points you in the right direction…


#3

@smegnl Just wondering if you have been able to create any progress…


#4

I got it using this plugin.