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

How can I use taxonomy with images metadata?

Started by Muut Archive 11 years ago · 2 replies · 286 views
11 years ago

Hi there, I have some images inside my page.
Each image is associated with a metadata file like this:

TXT
img01.jpg
img01.jpg.meta.yaml
img02.jpg
img02.jpg.meta.yaml
img03.jpg
img03.jpg.meta.yaml

Each yaml file has something like this for example:

YAML
description: a test description
taxonomy:
    tag: [blue,red,green]

How can I loop and filter only the "red" tagged images for example ?
I'm trying this on my template, but it's not working

TWIG
{% for myimage in taxonomy.findTaxonomy({'tag':['red']}) %}
    <li>{{ myimage.description }}</li>
{% endfor %}

I also tried using page.media.images but no luck.

Any tip ?

Cheers

11 years ago

I think I should have rephrased my questions and asked instead
"Is this possible ?".

Nevertheless I think I have found an alternative to achieve my goal.
I have changed my yaml file to look like this:

YAML
description: test description
color: red

And them on my template I'm using something like this:

TWIG
{% for myimage in page.media.images %}
   {% if myimage.color == "red" %}
      {{ dump(myimage.description) }}
   {% endif %}
{% endfor %}

Any thoughts ?

11 years ago

If that works, I think it looks like a solid solution. Media YAML just supports standard yaml syntax for storing attributes, no need to make it more complex than it needs to be. Usually the simplest solution is the best.

Suggested topics

Topic Participants Replies Views Activity
Archive · by Deleted User, 9 years ago
0 1332 9 years ago
Archive · by Muut Archive, 9 years ago
2 923 9 years ago
Archive · by Muut Archive, 9 years ago
2 4053 9 years ago
Archive · by Muut Archive, 9 years ago
1 2931 9 years ago
Archive · by Muut Archive, 9 years ago
3 1109 9 years ago