0

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 :

https://api.drupal.org/api/drupal/core%21themes%21stable%21templates%21field%21responsive-image.html.twig/8.2.x

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?

0

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, privacy policy and cookie policy

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