Ad

Twig Templating For Variables And Filters

- 1 answer

Having problems with correct output in October CMS twig: Using -

<img src="{{ asset('assets/img/flag-'~code~'.png'|theme) }}" class="flag">

And expecting http://xxx.dev/themes/theme/assets/img/flag-en.png in the src, however I'm getting http://xxx.dev/assets/img/flag-enhttp://xxx.dev/themes/theme/.png instead...

How can I solve this?

Ad

Answer

This should work (notice the parenthesis):

<img src="{{ asset(('assets/img/flag-'~code~'.png')|theme) }}" class="flag">

And the logic begind it is that the |theme is applied only to the `.png´ part and therefore it generates a broken url.

Ad
source: stackoverflow.com
Ad