How to match array values across arrays?

Viewed 39

Well, its 8 years or so ago, and I'm still trying to figure some of this out (How can I create linked tags from a comma separated list value in Stacey App?), but I'm making some better progress.

I have a few project.yml files in Stacey App/CMS:

1. /projects/design-project/project.yml

title: Design project
category: [Logo, Design]
content: +++
This is a design project.
+++

/projects/illustration-project/project.yml

title: Illustration project
category: [Illustration, Animation, Handmade, Design]
content: +++
This is an illustration project.
+++

/projects/video-project/project.yml

title: Video project.
category: [Video, Animation, Illustration]
content: +++
This is a video project.
+++

What I'd like is on a new template page, let's call it indvidual-category.html, it will look through all the available projects (these three for example, and display something like this:

Design: Design project, Illustration project
Logo: Design project
Illustration: Illustration project, Video project
Animation: Illustration project, Video project
Handmade: Illustration project
Video: Video project

So, I need Twig templating code to first look at the category: arrays in each project.yml, look through the array as individual items, check to see if in this example Design project has a match of any category array items with Illustration project and vice versa.

And, if that is the case, output the categories listed on the individual-category.yml page, showing each category across all the possible categories in all the project.yml files that exist, and show any projects that have matching categories in the same list.

What I'm aiming for is for you to be able to go to say /projects/category/design/individual-category.yml and all the projects that have Design in the category: key part of their project.yml will show up listed there.

I will have the correct hyperlinks and relevant thumbnails to each from there.

Is matching the right way to go here or is there some other way of comparing across arrays that I'm missing? I don't want to have to list each match individually, its more the case of if there is a match for that individual category, put all of that individual category together in one spot and display that.

Potentially this could turn into grabbing those matches and putting them into an array on the side that could be useful later?

A bit of help would be greatly appreciated!

0 Answers
Related