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

rhache created an issue. See original summary.

rhache’s picture

Issue summary: View changes
Chi’s picture

I 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.

Chi’s picture

Status: Active » Closed (won't fix)
thomas.frobieter’s picture

@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?

Chi’s picture

@thomas.frobieter that is "community driven" documentation. Which means you can edit it.

thomas.frobieter’s picture

Ouh thx, never noticed this in 10 years -_-

Done.