Symfony 2.7:资产组件不适用于 imagine_filter

Symfony 2.7 : asset component not working with imagine_filter

随着 Symfony 2.7 中资产组件的引入,我如何输出没有版本号的资产的相对 url?

我正在使用以下代码,但它不再起作用了:

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

资产函数输出带有版本号的 url,imagine_filter 未正确处理此问题:

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

我的配置:

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

理想情况下,我可以在保持此版本控制策略的同时使 imagine 过滤器正常工作 否则,停用图像的版本控制可能就足够了

感谢您的帮助!

您应该明确指向要用于具体资产的包:

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

直接对相对路径进行过滤,asset()可以看作是一种帮手:

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

您还可以将版本(第 4 个参数)设置为 false:

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