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

Community guidelines

Please keep discussions civil and on-topic. Repeated violations may lead to a temporary ban.

Content & Markdown

How to display sub tree structure as a ToC

Started by porru 5 years ago · 1 replies · 840 views
5 years ago

Is there any way in which I could achieve to display on a page all its sub tree pages as a ToC that updates by itself?

This would mean having a redirecting directory on a page. Something like this:


Documentation

TXT
Mail
    How to synch with Android
Cloud
    Using Nextcloud Calendar
    Importing existing contacts into Nextcloud
Mastodon
    Migrating from an instance to another

Just like a ToC, but instead of for the page's content, listing pages on sub directories.

5 years ago

@porru, Essentially, the logic is the same as how a menu is build.

  • See Quarks '/user/themes/quark/templates/macros/macro.html.twig'.
  • Or have look at the way the menu is created in theme Learn. This is the theme used for the docs

In essence:

  1. Loop through the child collection of 'pages' (or specific page)
  2. For each child, print its properties (e.g. title, description and url)
    a. For each child, check for children
    • For each child, go to 1

Suggested topics

Topic Participants Replies Views Activity
Content & Markdown · by Jochen, 8 months ago
6 96 8 months ago
Content & Markdown · by Ton Haarmans, 1 year ago
10 184 1 year ago
Content & Markdown · by Jan L'Am, 1 year ago
4 147 1 year ago
Content & Markdown · by Leonardo, 1 year ago
3 61 1 year ago
Content & Markdown · by belthasar, 1 year ago
4 255 1 year ago