Reputation: 997
i have a list of objects which has an image as an attribute(name of the image as a string) , i am looping this list in twig and i try to display the image in an img html tag which takes it's source of image through a symfony 'asset' path . this the twig part of code :
{% for offre in listeoffres %}
<li>
<img src="{{asset('images/')}} {{ offre.nomImage }}" alt="">
</li>
<li>
{{ offre.titre }}
</li>
{% endfor %}
Notes :
The database contains correct image names and the images already
exist in the correct folder (web/images
)
The '{{ offre.nomImage }}' displays correctly the image name that it's in the database (with the extension)
When i display {{asset('images/')}} {{ offre.nomImage }}
it shows:
/myproject/web/images/ image.jpg
Upvotes: 0
Views: 1993
Reputation: 2310
While your solution works, Tthe correct way to use the asset
function would be to pass the full path of the image to the function call:
{{ asset('images/' ~ offre.nomImage) }}
Upvotes: 1
Reputation: 997
I have solved it. The problem was the space between the asset and the image name.
So the image source should have been like this :
{{asset('images/')}}{{ offre.nomImage}}
Upvotes: 0