I’m looking for advices to achieve some kind of pages. After many tries I’m not sure what is the best option to do it.
Here’s a page I want to build:
Some standard content (text, titles, images…)
A list of hyperlinks to other pages
Some more standard content
Another list of hyperlinks to other pages
Some more standard content
I want these lists of hyperlink to be dynamics, meaning that each page in a list must belong to another user/pages directory and/or fit a taxonomy. For exemple, all pages in the “news” directory, or all pages with the “fruit” tag, or all pages in the “members” directory with the “administrator” or the “worker” tag.
I’m facing two problems here:
Problem 1:
I want the standard content to be easily editable, and the differents parts of the page to be easily movable. The best option for that seems to have all the standard content in a single markdown page, with specials “placeholders” that mark the position of the 2 hyperlinks lists.
I’ve found 2 options for this:
Enable twig processing in the frontheader and use a {% include ‘partials/list1.html.twig’ %} to position a list.
Use the inject plugin.
Not sure if the inject plugin is required, the first option seems ok to me. Can you confirm this is a good way to go ?
Or am I trying, with option 1, to use grav in a way it is not intended for ? Perhaps I must give up to offer this editing facilities and create a modular page that will break down the standard content in many markdown files, with the drawback that the template must be edited to rearrange the page order ?
Problem 2:
Assuming the option 1 is the right way to go, I’ve created a partial template for each hyperlink list. But I can’t find how to get a list of pages that belong to another user/pages directory and that fit at the same time a taxonomy with multiples conditions, like ‘category’=‘event’ AND (‘tag’=‘dinner’ OR ‘tag’='birthday"). I write here about the problem 2 because perhaps my difficulty here is related to a bad design choice in problem 1 ?
Thank you for your answers, can’t find the solution myself after hours reading the doc and searching the forum.
What you want are page collections, of which you can have more than one. The link below takes you to the Multiple Collections section, but you should familiarize yourself with the whole page.
Remember that generated pages get cached. So when you add new content, you may need to empty the cache for them to appear on this dynamic page.
As the link I posted shows, you have to create multiple collections and then use the methods (described further down the page) to combine them in whatever way you want. For an “OR” condition, use Collection::merge($collection2).
For the problem 1 (see fist post in this discussion) I ended up using the shortcode-core plugin. It allows me to create convenient tags, and my page markdown looks like:
Some standard content (text, titles, images…)
[links tags=dinner]
Some more standard content
[links tags=birthday,anniversary]
Some more standard content
For my problem 2 I have found no solution. I have solved my problem by rearranging my taxonomies, so I don’t need to filter at the same time by taxonomy and by folder anymore.
I’m not familiar enough with the finer points of page collections to comment on your problem #2. But for the sake of completeness, another solution to problem #1 is to use Modular Pages
Thanks for the input @Utis.
You’re right, modular pages deserve to be mentionned in this thread.
I haven’t choosen them because I want to provide to the persons who will keep the website up to date the most easy to learn solution I can find.
And also because the documentation say:
A Modular page, however, does not have child-pages.
Perhaps it’s still possible to have regular subpages, I need them, but I didn’t try. Even if it’s work, this would be a little bit confusing for the users to have modules and regular pages mixed in the subfolders.
From my in depth experience with WP I can say this kind of functionality is extremely powerful. I wish I had the ability to help get this into the Grav core as it would be a huge leap in ease of use (for the non-dev users we are often handing off the admin to).
Also, @lilive from my testing you can indeed have a modular parent page that also has child pages. I’m not sure why the documentation says that. Maybe it’s just not recommended as it could be confusing to other admin users?