I have a responsive image field inside two different paragraph types. I am on Drupal 8.3.7. I want to theme the module in one paragraph type but not the other. I want to render a modified version of this code :


I tried putting my modified code inside responsive-image--field_my_resp_image.html.twig but it is not being used. I can't seem to find the correct filename for a theming a responsive image from a specific paragraph type. Any ideas?

My goal is to render embedded CSS for a background image instead of the HTML picture element that responsive images uses. Is there a better method than what I'm attempting above?

1 Answer 1


I found a solution, but I'm honestly not happy with it. I can use 'responsive_image_style_id' to identify this responsive image. The problem with this approach is that it relies on specific keywords ('_style') in 'responsive_image_style_id' and if a site admin changes that, it will break :

function paia_theme_suggestions_responsive_image_alter(&$suggestions, $vars, $hook) {

  $newHook = str_replace('_style', '', $vars['responsive_image_style_id']);

  if ($newHook != $vars['responsive_image_style_id']) {
    $suggestions[] = $hook . '__' . $newHook;

It seems I am using entirely the wrong approach for this, and I should probably be rolling my own module or something totally different. But I have a deadline to meet and I need to move on.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.