-2

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.

Iter Ator
  • 8,226
  • 20
  • 73
  • 164

2 Answers2

2

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>') }}" />
j4ck50n
  • 69
  • 1
  • 2
1

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.

FTW
  • 922
  • 1
  • 7
  • 19