Quantcast
Channel: Issues for Drupal core
Viewing all articles
Browse latest Browse all 297731

Cannot Target Specific Image in Twig

$
0
0

Problem/Motivation

There seems to be no way to target a specific image field deeper than the field template. When enabling Twig debug mode in Drupal 8 beta 1 and 2, there are no twig name suggestions that can replace the default output created by the image.html.twig file.

A possible use case would be to use the image as a css background image or to link the image file for a jquery lightbox script. This kind of regression is going to make themers and site-builders be at the mercy of having to use a custom image formatter module or something like the ds module. I, for one, don't like to have to rely on ds if it can be helped because I prefer to stick with core whenever possible.

Some twig logic within the image.html.twig file itself could be used to target a specific image field but seems like it would be too much of a hack. One of the things I love about Drupal 7 php templates is that you have better control of the image output from the theme layer without having to install field formatter modules.

I'm guessing that theme builders could work around this issue by using a hook to delegate the image template based on field name or image style. I am planning on learning how to implement my own image formatters for Drupal 8, but I still think it should be possible to manipulate the output of images in this way. It might turn off new Drupal users who are seeking flexible handling of image files using Twig.

Proposed resolution

A resolution would be for Drupal to recognize twig templates such as this :

<!-- FILE NAME SUGGESTIONS:
   * image--node--field-field_name--page.html.twig
   * image--node--field-field_name.html.twig
   * image--node--page.html.twig
   * image--field-field_name.html.twig
   x image.html.twig (only template currently recognized)
-->

I don't know what the performance implications are regarding this, but I strongly suggest that an approach like this is considered because image handling is very important for Drupal's appeal to less tech savvy themers.


Viewing all articles
Browse latest Browse all 297731

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>