Modular page with different collections

I am trying to set a page that can show the first item of each of the 3 categories I am planning to use in my website.

I thought of creating a modular page, and to use 3 different modules to create these collections and get the latest page on each of my categories.

But I don’t get to achieve this.

first of all, is this possible?
second, what type should the module be?
I created a modular.md on the root, and for each of the modules, a folder with a .md file inside, but I am not getting anything.

at a second step I thought it might have to do with the template,

I am using the quark theme (ootb).
I thought of creating a new file under modular folder (something like article.html.twig) do try if that is a possible solution, but this type does not appear as an option to be selected.

So I am clearly doing everything wrong :sweat_smile:

any advice?
thanks!

@kernel52,

Try the following:

  • Download skeleton Blog Site which contains pages with several tags.
  • Create new page /user/pages/02.test/test.md
  • Create 3 collections in page
    ---
    mushroom:
      items:
        '@taxonomy.tag': mushroom
      limit: 1
      order:
          by: date
          dir: desc
    
    travel:
      items:
        '@taxonomy.tag': travel
      limit: 1
      order:
          by: date
          dir: desc
    
    architecture:
      items:
        '@taxonomy.tag': architecture
      limit: 1
      order:
          by: date
          dir: desc
    ---
    
    # My page with last items of 3 categories
    
  • Create new template /user/themes/quark/templates/test.html.twig with the following content:
    {% extends 'partials/base.html.twig' %}
    
    {% block content %}
    
      {{ page.content|raw}}
    
      <h2>Looping 3 collections</h2>
    
      {% for child in page.collection('mushroom') %}
        {% include 'partials/blog-list-item.html.twig' with {blog: page, page: child} %}
      {% endfor %}
    
      {% for child in page.collection('travel') %}
        {% include 'partials/blog-list-item.html.twig' with {blog: page, page: child} %}
      {% endfor %}
    
      {% for child in page.collection('architecture') %}
        {% include 'partials/blog-list-item.html.twig' with {blog: page, page: child} %}
      {% endfor %}
    
      <h2>Or merge three collections into 1</h2>
    
      {% set collection = page.collection('mushroom').merge(page.collection('travel')).merge(page.collection('architecture')) %}
    
      {% for child in collection %}
        {% include 'partials/blog-list-item.html.twig' with {blog: page, page: child} %}
      {% endfor %}
    
    {% endblock %}
    
  • Browse to page http://yourdomain/test
    It will show you two lists of pages, where each list contains the last item of each ‘tag’.

Note:

  • When merging collections, the result will be deduped. Meaning: If a page has both tag ‘mushroom’ and ‘travel’, the page will be shown only once.
1 Like

thanks pamtbaau!
I am very grateful for the detailed explanation you provided.

I’m giving it a try and will get back to you to (hopefully) confirm that it is as perfect as it looks :slight_smile:

@kernel52, Have you had the chance to experiment with the collections?

Hi pamtbaau,

I did manage to test. It works as a charm!
I changed the items to be the liat of items under a page and got exactly what I wanted!

I now have to learn how to work with the templates to import my old drupal template into grav :sweat_smile:

Any hints are more than welcome :pray: