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

Cant' access meta data from files

Solved by pamtbaau View solution

Started by 01K 5 years ago · 2 replies · 557 views
5 years ago

Hi there!
having trouble accessing meta data from files.
I have a gallery and meta.yaml files.
The name of files and meta filess follow the rules:

TXT
00x-image.jpg
00x-image.jpg.meta.yaml

Inside meta.yaml file I've got the following information:

YAML
meta.alt_text: My alt text
meta.description: Description

And I'm publishing a photo gallery:

TWIG
    <div id="photoswipe-gallery-id" class="row justify-content-center">
        {% for item in page.media.images %}
            <a href="{{ item.url|e }}" class="gallery-item" data-size="{{ item.width ~ 'x' ~ item.height }}">
                <img src="{{ item.cropResize(500, 250).url|e }}" loading="lazy" alt="{{ item.meta.alt_text }}"/>
            </a>

            {{ dump(item) }}
        {% endfor %}
    </div>

In the past project I've used to access meta data in such way: {{ item.meta.alt_text }}

But now I'm getting null data.

The dump(item) shows this information, and meta.alt_text is present in array
But it seems I'm doing something wrong...

image|690x433

5 years ago Solution

@01K, Try removing the meta. inside the yaml file:

YAML
alt_text: My alt text
description: Description

Changing {{ item.meta.alt_text }} to {{ item.meta.meta.alt_text }} won't work. Dotted names are valid Yaml field names but the dot does not have any special meaning. They are not separators. Twig will try to interpret the dot as a separator and will therefor not be able to find the value.

👍 1
last edited 02/06/22 by pamtbaau
5 years ago

Thank you very much!

Suggested topics

Topic Participants Replies Views Activity
General · by jean-louis67, 3 weeks ago
2 308 3 weeks ago
General · by Andy Miller, 3 weeks ago
0 310 3 weeks ago
General · by Veehem, 4 weeks ago
0 263 4 weeks ago
General · by milkboy, 4 weeks ago
0 264 4 weeks ago
General · by ian russell, 1 month ago
2 335 1 month ago