4

Symfony2 + Assetic + Twigに画像のURLを生成させるより短い方法はありますか?

{% image '@ACMEBundle/Resources/public/img/longer.png' %}
  <img src="{{ asset_url }}" />
{% endimage %}

理想的には、次のようなものです。

<img src="{{ bundle_resource_url('@ACMEBundle/Resources/public/img/shorter.png') }}" />
4

1 に答える 1

7

アセットがWebディレクトリにある場合は、代わりにこれを使用してください。

<img src="{{ asset('bundles/acme/img/shorter.jpg') }}" />

これを実行することで、Asseticにアセットをインストールさせることができます。

app/console assets:install path/to/web

あなたのウェブルートはどこpath/to/webにありますか。

于 2012-12-07T19:52:12.090 に答える