Jack Plum Jack Plum - 4 months ago 21
Twig Question

How to replace string with variable in Twig

{% image '@AppBundle/Resources/public/images/florida.png'%}
<img src="{{ asset_url }}" alt="Example" height="200" width="200"/>
{% endimage %}


I have this code here from my twig file. I want to load an image called "florida.png from the file location:"@AppBundle/Resources/public/images/florida.png". I want to replace the "@AppBundle/Resources/public/images/florida.png" with a string variable and was wondering how I could do this? Any help would be of great assistance!

Answer

Is this what you're after?

<img src="{{ asset('bundles/app/images/florida.png') }}" alt="Example" height="200" width="200"/>