I would like to display an image on my page, like this:
<img src="{{ asset('image.png') }}"/>
The image is located in assets/image.png
If I open the page, the result is this:
<img src="/image.png"/>
But the image can not be found on that url. I suspect, that the image.png
has to be copied somehow to the /public directory
, but Symfony did not copy it there, and I have no idea which command to run, to automatically copy the required assets like that.
Create folder in public
, for example images
, and put your image to this folder. Then in template you should use your image as follow
<img src="{{ asset('images/<YOUR_IMAGE>') }}" />
Unless you do a special treatment on the image, you don't really need to put it in the assets folder. You can just put it in the public folder, in a subfolder ideally.
Or you can keep it in the assets folder, and use this :https://symfony.com/doc/current/frontend/encore/copy-files.html
To copy it with webpack on build time.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.