【问题标题】:Is it possible to create a conditional path to an asset using assetic and twig?是否可以使用资产和树枝创建资产的条件路径?
【发布时间】:2013-04-10 18:08:51
【问题描述】:

基本上,我想知道以下是否可行:

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

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

【问题讨论】:

  • 编辑:代码 sn-p 在评论中完全不可读,请参阅下面的答案。

标签: php symfony twig assetic


【解决方案1】:

你为什么不把 if 放在 asset-call 之外,像这样:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2022-06-10
    • 2023-03-14
    • 1970-01-01
    • 2015-11-24
    • 1970-01-01
    • 1970-01-01
    • 2023-03-31
    相关资源
    最近更新 更多