jlb
jlb

Reputation: 19970

How to use assetic to render an (unoptimised) image tag in Symfony2 + Twig

Is there a shorter way to have Symfony2 + Assetic + Twig generate image urls than:

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

Ideally, something like:

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

Upvotes: 4

Views: 7571

Answers (1)

lifo
lifo

Reputation: 2893

If your assets are in your web directory then use this instead:

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

You can have Assetic install your assets for you by running this:

app/console assets:install path/to/web

Where path/to/web is your webroot.

Upvotes: 7

Related Questions