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

Alt text in responsive images. Posible?

Started by Muut Archive 10 years ago · 2 replies · 513 views
10 years ago

Is it possible to attach to responsive images alt text without creating sample-image.jpg.meta.yaml?

TWIG
{% for image in page.media.images %}
<img class="" {{ image.sizes('80vw').html() }}>
{% endfor %}

combine

TWIG
alt="{{ page.parent.title }} | {{ page.title }}"

Thanks.

10 years ago

Mhm, maybe like this?

TWIG
{% for image in page.media.images %}
   {{ image.sizes('80vw').html(page.parent.title, page.title, 'myClassName') }}
{% endfor %}

The html() function, outputs the image tag and you can add the alt and title tag. Never tried with responsive images though, but see here:
https://learn.getgrav.org/content/media#htmltitle-alt-classes

Suggested topics

Topic Participants Replies Views Activity
Archive · by Deleted User, 9 years ago
0 1359 9 years ago
Archive · by Muut Archive, 9 years ago
2 936 9 years ago
Archive · by Muut Archive, 9 years ago
2 4066 9 years ago
Archive · by Muut Archive, 9 years ago
1 2956 9 years ago
Archive · by Muut Archive, 9 years ago
3 1121 9 years ago