I’m in the process of adding a “page link” functionality to the Visual Markdown Editor by @DieserJonas.
Some of my clients asked for a more visual way of selecting the page for a page link. Otherwise you have to copy the URI by hand.
That’s how it looks right now:
Anyway, I seem to over-complicate the process of listing every level of pages grouped by their parents.
I don’t really want to have over 100 lines of code just to go through all the children, and their children, and their children, … and then somebody adds a fifth layer to their Kirby site.
I tried to use the ->groupBy() function on the $site->index() variable. But that didn’t work. The children will have to be in the parents element and I couldn’t figure that out.
What’s the best way to list an infinite amount of pages and all of their descendants? I’m sure there’s an easy way.
Sorry, but I’ll have to ask something concerning this again.
The treemenu script uses a snippet to call the function again. But I can’t use a snippet, since I’m working on a custom field. Thanks to @lukasbestle I knew what these recursive functions are called, though. And I could google it. So I tried to declare a PHP function with a variable and call it when I want to list the next layer. It won’t work no matter what I try.
Well, I think the main issue was that you didn’t call the function in the first code snippet you posted. The last line of the second one does call it, so that’s why it works now.
It’s not exactly “old”. It was an extension of the Visual Markdown Editor, now it’s also an extension for the regular textarea field. So, both have the right to live