Mixing standard content and dynamic content within a page

Hello everybody,

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.

Thank you Perlkonig,

I don’t see how to resolve this problem in this page of the documentation.
For exemple…

---
process:
    twig: true
events:
    items:
        '@page.descendants': '/news'
---
{% include 'partials/list.html.twig' with { 'pages':page.collection('events') } %}

… is ok and allow list.html.twig to create a list of hyperlinks for all the pages in the /news directory.

But:

events:
    items:
        '@taxonomy':
            tag: [dinner, birthday]
------

give me only the pages with the 2 tags and I can’t figure how to use the OR operator available in findTaxonomy.

events:
    items:
        '@page.descendants': '/news'
        '@taxonomy':
            tag: [dinner, birthday]
------

give me the same than just @page.descendants’: ‘/news’ without taxonomy.

I can do:

{% set events = taxonomy.findTaxonomy( {'tag':['dinner', 'birthday']}, 'or' ) %}
{% include 'partials/list.html.twig' with { 'pages':events } %}

and this is fine for the tags but I can’t figure how to get only the pages in the ‘news’ folder that fit this taxonomy.

But all these tries help me to think: a solution can be to create a special tag for all the pages I want in a list. This is simpler.

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).

Thanks for pointing me this. I read that, and I can create 2 collections in the frontmatter:

collection1:
    items:
        '@taxonomy':
            tag: [dinner]
collection2:
    items:
        '@taxonomy':
            tag: [birthday]

And merge them like you say. But what I want is the pages tagged ‘dinner’ or ‘birthday’ that are in the ‘/news’ directory. And

collection1:
    items:
        '@page.descendants': '/news'
        '@taxonomy':
            tag: [dinner]

doesn’t filter the ‘/news’ pages with the ‘dinner’ tag.

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

You could create a folder structure like:

01.Page/
    modular.md
    _content1/
        item.md
    _links1/
        linklist.md
    _content2/
        item.md
    _links2/
        linklist.md

And define the link collections in the frontmatter of each linklist.md. That’s the way, I, personally, would prefer.

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.

To me the ideal solution to Problem #1 would be setting up a “Conditional Field” as proposed in this thread: Conditional field - Creating a 'Flexible Content Field' (like 'Advanced Custom Fields' wordpress plugin)

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?