Zied R.
Zied R.

Reputation: 4954

Pass parameter to twig view in Symfony2

I have a twig page which I included a picture , this picture will be loaded from a folder (uploads) , but the name (example.jpg) is loaded from the database :

<img src="{{ asset('uploads/example1.jpg') }}">

this works for me , but I want now that example1.jpg will be passed to the twig page :

return $this->render('MyAppExampleBundle:Default:index.html.twig', array(
            'logo' => $logo)); //$logo = 'example1.jpg'

How I can do this?

I have tried <img src="{{ asset('uploads/{{logo}}') }}"> but this is illogic and doesn't work .

Any help plz

Upvotes: 0

Views: 244

Answers (2)

bedoui_mouoifek
bedoui_mouoifek

Reputation: 19

try {{ asset('uploads/' ~ logo) }}

Upvotes: 1

Ahmed Siouani
Ahmed Siouani

Reputation: 13891

What about,

<img src="{{ asset('uploads/' ~ logo) }}"> 

{{ ... }} twig delimiters can't be nested. You should then use concatenation.

Upvotes: 2

Related Questions