Symfony 2.7 : asset component not working with imagine_filter
Asked Answered
C

2

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 !

Carilla answered 18/10, 2015 at 16:29 Comment(0)
S
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) }}">
Soldier answered 29/10, 2015 at 13:58 Comment(1)
The use of the fourth parameter is deprecated in Symfony 2.7Saeger
I
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"> 
Implead answered 18/10, 2015 at 18:19 Comment(1)
Have you tried with version_format: null instead of version_format:'' ?Saeger

© 2022 - 2024 — McMap. All rights reserved.