brunodd
brunodd

Reputation: 2584

Symfony2 - Asset function to images

I know I can use this as an asset function:

<img src="{{ asset('images/logo/logo.png') }}" alt="Logo">

But is there a way to use an asset function using another function? Like this:

<img src="{{ asset('images/logos/{{ dominantItem.generateLogos | lower | replace({' ': '-'}) }}.png') }}" alt="Logos">

Obviously the code above is not working, am I missing something?

Upvotes: 0

Views: 24

Answers (1)

Paul
Paul

Reputation: 141827

You can't nest twig tags like that, but you can use string concatenation to achieve what you want:

<img src="{{ asset('images/logos/' ~ (dominantItem.generateLogos | lower | replace({' ': '-'})) ~ '.png') }}" alt="Logos">

Upvotes: 3

Related Questions