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

Community guidelines

Please keep discussions civil and on-topic. Repeated violations may lead to a temporary ban.

General

Complex Collections

Solved by pamtbaau View solution

Started by Norbert 4 years ago · 10 replies · 487 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

Of course, you are right. Thx.

I did it yesterday like this:

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

It seems to work fine in my case too.

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

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 Jerry Hunt, 4 days ago
2 85 13 hours ago
General · by pamtbaau, 18 hours ago
1 60 17 hours ago
General · by Andy Miller, 1 day ago
0 47 1 day ago
General · by Marcel, 12 months ago
6 350 5 days ago
General · by Duc , 6 days ago
3 44 5 days ago