Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
By ilclaudio on
Hi guys,
I'm modifying the template views-view-fields.html.twig in a custom theme (in Drupal8).
In this template, I'd like to show an image-field not in its full size but as a thumbnail or in a smaller size.
Is it possible?
How should I change this code?
{{ fields.field_photo.content}}
Thank you very much.
claudio
Comments
You will want markup
You will want markup something like the following in the appropriate theme file:
Drupal includes an image style manager found at:
admin/config/media/image-styles
in the Drupal admin UI
When implementing relevant portions of your theme, you refer to the "style" of the image when referencing the image in your theme's code.
spritefully yours
Technical assistance provided to the Drupal community on my own time ...
Thank yous appreciated ...
Hi sprite,
Hi sprite,
thank you for your time.
The code you write probably is the D7 solution to the problem, I don't think that it is possible to add PHP code to Twig templates on D8.
On D8, at the moment, I've defined a new style in the section "admin/config/media/image-styles" as you said.
Then I've chosen in the View definition Configure field --> image style my custom style and in the template file I'm using this code:
{{ fields.field_photo.content}}
It seems to work.
cld
Hi ilclaudio,
Hi ilclaudio,
change image format from 'mange display'.
1. Navigate to the Content types page (Administer > Structure > Content types).
2. In the table, locate the row that contains your content type and click the manage display link.
3. Specify the "thumbnail" format.
4. then click Save.
thanks