Getting template suggestions for fields based on the view made in which they are appearing

Drupal 8 does not provide template suggestions for fields per the view mode of the content they are on. (I was wrongly blaming Display Suite for them not being there.)

Here are the file name suggestions for the image field on an article node shown with the full view mode:

<!-- FILE NAME SUGGESTIONS:
   * field--default--node--field-image--article.html.twig
   * field--default--node--article.html.twig
   * field--default--node--field-image.html.twig
   * field--default--field-image--article.html.twig
   * field--default--article.html.twig
   * field--default--field-image.html.twig
   * field--default.html.twig
   * field--theme-ds-field-default.html.twig
   * field--node--field-image--article.html.twig
   x field--node--field-image.html.twig
   * field--node--article.html.twig
   * field--field-image.html.twig
   * field--image.html.twig
   * field.html.twig
-->

Here are the file name suggestions for the image field on an article node shown with the card view mode:

<!-- FILE NAME SUGGESTIONS:
   * field--default--node--field-image--article.html.twig
   * field--default--node--article.html.twig
   * field--default--node--field-image.html.twig
   * field--default--field-image--article.html.twig
   * field--default--article.html.twig
   * field--default--field-image.html.twig
   * field--default.html.twig
   * field--theme-ds-field-default.html.twig
   * field--node--field-image--article.html.twig
   x field--node--field-image.html.twig
   * field--node--article.html.twig
   * field--field-image.html.twig
   * field--image.html.twig
   * field.html.twig
-->

Spot the difference? Yeah, neither can the templating system, and so, neither can the CSS. So stupid to break fundamental Drupal theming functionality.

display suite field template suggestions per view mode

Oops. Turns out this is a limitation in Drupal.

And the great leymannx fixed it, in the module we co-maintain (he’s done the vast majority of the work).

Here’s his explanation how:

https://drupal.stackexchange.com/questions/269595/how-to-get-the-field-template-for-view-modes-to-work

Here’s our module: https://www.drupal.org/project/twigsuggest