I'm not sure this can be done, but I'm trying to insert a responsive image in a twig template, using Twig Tweak's drupal_image
function, but with a image in my theme's images folder.
I've tried:
{{ drupal_image(path_to_img, 'responsive_style', {alt: 'Alternative text', title: 'The title'}, true) }}
and
{{ drupal_image(path_to_img, 'responsive_style', responsive=true) }}
Both options output nothing. I know that my path is correct because it works with plain image (ie <img src="{{ path_to_img }}">
). Is there any way to get this function to work with more than files with a public URI? Or is there a way to convert a path to a theme image to a public URI? Or am I missing something?
If this can't done it would certainly be a good feature request.
Thanks!
Comments
Comment #2
rhache CreditAttribution: rhache commentedComment #3
Chi CreditAttribution: Chi commentedI think that's not possible due Drupal core limitation. See the following thread for details.
https://www.drupal.org/forum/support/module-development-and-code-questio...
Technically we can support this once core provides stream wrappers to access extension files.
Comment #4
Chi CreditAttribution: Chi commentedComment #5
thomas.frobieter@Chi: Could you please add a hint to the 2.x docs? Very confusing that the responsive attribute just prints out the fallback image of the responsive style.
https://www.drupal.org/docs/contributed-modules/twig-tweak-2x/cheat-sheet
"Due to a Drupal Core limitation, the responsive option will just print out the fallback image style as simple img." or something like that?
Comment #6
Chi CreditAttribution: Chi commented@thomas.frobieter that is "community driven" documentation. Which means you can edit it.
Comment #7
thomas.frobieterOuh thx, never noticed this in 10 years -_-
Done.