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

Cant' access meta data from files

Solved by pamtbaau View solution

Started by 01K 4 years ago · 2 replies · 419 views
4 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

4 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
4 years ago

Thank you very much!

Suggested topics

Topic Participants Replies Views Activity
General · by Jerry Hunt, 4 days ago
2 125 19 hours ago
General · by pamtbaau, 1 day ago
1 89 24 hours ago
General · by Andy Miller, 2 days ago
0 73 2 days ago
General · by Marcel, 12 months ago
6 382 5 days ago
General · by Duc , 6 days ago
3 69 6 days ago