Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to create a conditional path to an asset using assetic and twig?

Basically, I want to know if something like the following is possible:

<img src="{{ asset('bundles/acme/images' {% if something is defined %}'-blah{{ someId }}'{% endif %} '.png') }}" />

According to this the answer is likely no, but I want to make sure.

like image 344
Major Productions Avatar asked Dec 22 '25 17:12

Major Productions


1 Answers

Why don't you put the if outside the asset-call like this:

<img src="
{%- if something is defined -%}
    {{ asset('bundles/acme/images-blah' ~ someId ~ '.png') }}
{%- else -%}
    {{ asset('bundles/acme/images-blah.png') }}
{%- endif -%}
" />
like image 70
dbrumann Avatar answered Dec 24 '25 07:12

dbrumann