Mirage
Mirage

Reputation: 31548

Is there any easy way to set image asset in symfony 2

I have the html template where i image is referenced as images/logo.gif

Now in Symfony templates i have to use

src="{{ asset(['images/', 'logo.gif']|join) }}"

Is it possible to use something like

src="{{ asset(['images'])}}/logo.gif

so that i need not replace all the image tags in html file. Then i can find and replace easily. Othwise i have to manually change all image occurances

Upvotes: 0

Views: 413

Answers (1)

Jakub Zalas
Jakub Zalas

Reputation: 36191

Why don't you just use this?

src="{{ asset('images/logo.gif') }}"

EDIT:

I didn't try it but concatenation should work as well:

{% set imageDir = 'images/' %}

src="{{ asset(imageDir ~ 'logo.gif') }}"

However, it introduces unnecessary complexity. I don't see anything wrong in a hard coded version. You don't change it often.

Upvotes: 2

Related Questions