How to display images in symfony

0

I'm starting in symfony and would like to know how to display an image correctly. I'm changing the index.html.twing and it stays in app / resource / view / default / and the base.html.twing that stays in app / resource / view /. I put <img src="../../../src/AppBundle/Resources/public/imagens/logo.png" />

<img src="{{ asset('imagens/dev-total-logo.png') }}" />

How is the right way to do this?

    
asked by anonymous 19.07.2016 / 23:11

1 answer

1

The correct form is the second one:

<img src="{{ asset('imagens/dev-total-logo.png') }}" />

There are several reasons for this. The first one is that this way your application can display the image regardless of where your static files folder is, as long as Symfony knows where it is.

In addition, images (as well as any other static file, such as a CSS file or a JS file) must be in the web/ folder. If your static files are within , ie inaccessible, you must use the assets:install command to have the files copied (or linked) to the public folder.

In Symfony 2.x:

app/console assets:install 

In Symfony 3.x:

bin/console assets:install
    
20.07.2016 / 09:07