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

Complex Collections

Solved by pamtbaau View solution

Started by Norbert 4 years ago · 10 replies · 582 views
4 years ago

I want to create a collection of all pages from a given directory but with an additional criterion which is a specific value in the taxonomy.

I followed the example of Complex Collections from the documentation but I have a problem with it.

I have this structure:
/services/brakes/offer.md

Contents of the offer.md file:

YAML
---
title: Brakes
taxonomy:
   branch: ['Las Vegas', 'Montreal']
---

I also have:
/branches/new-york/section.md

Contents of the section.md file:

YAML
---
title: New York
content:
    items:
      - '@page.children': '/services'
      - '@taxonomy':
            branch: ['New York']
---

And it shows me Brakes...

4 years ago

@q3d,

According the first paragraph of the docs on Complex Collections:

[...] the resulting collection will be the sum of all the pages found from each of the collection definitions.

Since /services/brakes/offer.md is a child of /services it will be included in the result.

4 years ago

😊

Is there a way to define a collection so that it does not contain pages with e.g. a specific value in the taxonomy?

4 years ago

@q3d, It depends on what you are trying to achieve...

Please show:

  • A part of your folder structure that is involved in the collection.
  • Show filenames and relevant assigned categories per file
  • Which pages you would like to be added to the collection.
4 years ago

Thank you for your help.

The structure is as in the first post. I have a service directory. In the service directory, a directory for each service with a .md file. In the .md file in the taxonomy section, I have entered the branches where the service is available.

On the branch page (modular) in the services section, I want to display only the services available in this branch.

4 years ago

@q3d,

YAML
---
title: New York
content:
    items:
      '@taxonomy.branch':  'New York'
---
4 years ago

But I also wanted to use this taxonomy in other places, e.g. to mark customer reviews.

/testimonials/john-doe/testimonial.md

testimonial.md:

YAML
taxonomy:
   branch: 'New York'

What you propose will get all pages from both the services directory and the testimonials directory.

I think I need to rest for a while :)

4 years ago Solution

@q3d,

I asked for a detailed description of your situation for a reason... For clarity and preciseness.

You stated your goal as:

On the branch page (modular) in the services section, I want to display only the services available in this branch.

My answer applies to that description.

But I also wanted to use this taxonomy in other places, e.g. to mark customer reviews.

Now you are changing the situation. You're adding an extra folder in which the branch taxonomy is also being used and you are changing the goal...

I think I need to rest for a while

No no, just read the docs on Complex Collections again.

YAML
---
title: New York
content:
  items:
    '@taxonomy.branch':  'New York'
  filter:
    type: offer
---
last edited 11/24/22 by pamtbaau
4 years ago

@q3d, You are already differentiating pages using different templates. Adding an extra category tag to differentiate seem like an overhead...

Although the template's blueprint can set the category automatically, it still seems unnecessary...

4 years ago Norbert Of course, you are right. Thx. I did it yesterday like this: --- title: New York content…

As usual, you're right. That's why at first I didn't want to add an extra tag and was looking for another solution. Because I didn't understand that type: 'blog' means template page.

The solution you provided is perfect in my case:

YAML
---
title: New York
content:
  items:
    '@taxonomy.branch':  'New York'
  filter:
    type: offer
---

Thx!

Suggested topics

Topic Participants Replies Views Activity
General · by jean-louis67, 3 days ago
2 79 2 days ago
General · by Andy Miller, 6 days ago
0 144 6 days ago
General · by Veehem, 1 week ago
0 144 1 week ago
General · by milkboy, 1 week ago
0 138 1 week ago
General · by ian russell, 2 weeks ago
2 225 2 weeks ago