是否可以使用asset和twig来创建一个资源的条件路径?


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

基本上,我想知道是否有可能:

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

根据这个答案很可能是否定的,但是我想确定一下。

为什么不像这样把if放在asset调用之外呢?

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