Skip to content
Grav 2.1 is out: every page speaks Markdown. Read the announcement →

Cant' access meta data from files

Solved by pamtbaau View solution

Started by 01K 5 years ago · 2 replies · 634 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 jeremycherfas, 1 week ago
4 181 2 days ago
General · by lynbor, 6 days ago
2 122 3 days ago
General · by Old Man Umby, 1 week ago
1 100 1 week ago
General · by Sebastian, 1 week ago
1 124 1 week ago
General · by Andy Miller, 3 weeks ago
0 248 3 weeks ago