8

With the introduction of the asset component in Symfony 2.7, how can I output the relative url of an asset without a version number ?

I am using the following code whcih does not work anymore :

<img src="{{ asset('images/user.png') | imagine_filter('default') }}" alt="Image de profil" class="img-circle whitebg">

The asset function outputs an url with a version number and this is not handled properly by the imagine_filter :

http://mywebsite.com/media/cache/resolve/default/images/user.png%3Fversion=v1.0

My config :

framework:
    assets:
        version: 'v1.0'
        version_format: '%%s?version=%%s'
        base_path: ~
        packages:
            images:
                base_path: /images
                version_format: ''

Ideally I would be able to make the imagine filter work while keeping this versionning strategy Otherwise, deactivating the versioning for images could be good enough

Thanks for your help !

Sébastien
  • 5,263
  • 11
  • 55
  • 116

2 Answers2

7

Apply the filter to the relative path directly, asset() can be seen as a sort of helper:

<img src="{{ asset('user.png'|imagine_filter('default')) }}">

You can also sett the version (4th parameter) to false:

<img src="{{ asset('user.png'|imagine_filter('default'), null, false, false) }}">
Rvanlaak
  • 2,971
  • 20
  • 40
0

You should explicitly point to the package that you want to use for concrete asset:

<img src="{{ asset('user.png', 'images') | imagine_filter('default') }}" alt="Image de profil" class="img-circle whitebg"> 
Michael Sivolobov
  • 12,388
  • 3
  • 43
  • 64