Variables in asset path #163

biruwon opened this Issue Jan 29, 2013 · 2 comments


None yet

3 participants


I'm trying to do image optimization following the documentation:

My images path are build with a variable like that:

{% iconPath = "bundles/mybundle/images/" ~ name  ".jpg" %}

If a use twig function:

            bin: path/to/jpegoptim
            jpegoptim: ~

In twig:

<img src="{{ jpegoptim(iconPath) }}" alt="Example"/>

Fatal error: Call to undefined method Symfony\Bundle\AsseticBundle\Twig\AsseticNodeVisitor::getContext() in /myProjectPath/vendor/bundles/Symfony/Bundle/AsseticBundle/Twig/AsseticNodeVisitor.php(83) : eval()'d code on line 1

So I tried this without twig function:

{% image iconPath %}
filter='jpegoptim' output='/images/*.jpg' %}
<img src="{{ asset_url }}" alt="Example"/>
{% endimage %}

But I read from @kriswallsmith that assetic doesn't support variables.

Any solution? I'm using Symfony2.0.20 and AsseticBundle v2.0


Assetic needs an exhaustive list of possible images to optimize them before production. You cannot use {% image here because Assetic has no clue about your variable.

If you need to manage dynamic image URLs, your application should handle it on his own because many problems can start from this, especially if image list starts to change.

Since i's a very application-oriented business, you should handle this on your own. If you want to optimize it, optimize on import and serve them via a regular <img src="{{ asset_url('images/foo.png) }}. asset_url is compatible with variables.

Symfony member

Closing in favor of kriswallsmith/assetic#133

@stof stof closed this Oct 14, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment