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.

Content & Markdown

(solved) Image derivatives from file upload

Started by Artem Artemov 9 years ago · 1 replies · 821 views
9 years ago

I am having a bit of trouble being able to use Grav's responsive image srcset feature with images that a user would upload from admin. Since it returns an array I wasn't sure if it was possible to pass the same flag somehow or if at all possible since I am only able to return a path.

I have tried this:

TWIG
{% for f_image_path in p.header.project_featured_image %}
   {% set f_image = f_image_path.path.derivatives(460,1280,120).html %}
   {{ f_image }}
{% endfor %}

but no luck. Also not having luck with something like
{{ p.header.project_featured_image.derivatives( 460, 1280, 120 ).html }}

This works {{ p.media.images|first.derivatives( 460, 1280, 120 ).sizes('100vw').html }} but of course if I were to add more images that are part of the "project" it will display the last uploaded one.

9 years ago

Got it working!

TWIG
{% for featuredimage in page.header.project_featured_image %}
  {{ page.media[featuredimage.name].derivatives(460,1280,120).sizes('100vw').html }}
{% endfor %}

Suggested topics

Topic Participants Replies Views Activity
Content & Markdown · by Jochen, 8 months ago
6 94 8 months ago
Content & Markdown · by Ton Haarmans, 1 year ago
10 184 1 year ago
Content & Markdown · by Jan L'Am, 1 year ago
4 146 1 year ago
Content & Markdown · by Leonardo, 1 year ago
3 60 1 year ago
Content & Markdown · by belthasar, 1 year ago
4 254 1 year ago