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

sprite’s picture

You will want markup something like the following in the appropriate theme file:


<img src="<?php print image_style_url('small', $node->field_image[$lang][$key]['uri']); ?>" alt="<?php print $node->field_image[$lang][$key]['alt']; ?>" title="<?php print $node->field_image[$lang][$key]['title']; ?>"/>

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 ...

ilclaudio’s picture

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

ramesh_singh’s picture

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