Add image style to a upload file in twig

Created on 29 May 2024, 6 months ago

I am using a file upload field; if the field is image type, then I want to create an image style. I have installed the twig tweak module. But still does not work. using a view to call file fields and view template

{% if file_exr == 'mp4' %}
<video width="100%" height="auto" controls>
  <source src="{{ fields.field_upload_file.content }}" type="video/mp4">  
</video>
{% else %}
<img src="{{ fields.field_upload_file.content|image_style('medium') }}">
{% endif %}
🐛 Bug report
Status

Active

Version

1.0

Component

image.module

Created by

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Production build 0.71.5 2024