使用变量的 Symfony Assetic 函数
Symfony Assetic function using with variable
<img src="{{ asset("assets/img/sample.jpg") }}"/>
我想使用 sample.jpg
和过滤器
{% image "assets/img/sample.jpg" filter="jpegoptim" %}
<img src"{{ asset_url }}"/>
{% endimage %}
这里应有尽有
但我想从变量中获取文件。像这样:
{% set image = "sample.jpg" %}
{% image "assets/img/"~image filter="jpegoptim" %}
<img src="{{ asset_url }}"/>
{% endimage %}
错误:
Unexpected token "name" of value "image"
如果我在此配置下使用 twig jpegoptim 函数
#config.yml
assetic:
debug: '%kernel.debug%'
use_controller: '%kernel.debug%'
filters:
jpegoptim:
bin: /usr/bin/jpegoptim
strip_all: true
max: 80
twig:
functions:
jpegoptim: ~
模板文件:
<img src="{{ jpegoptim("assets/img/"~image) }}/>
错误:
Notice: Undefined index: jpegoptim in . (which is being imported from "/var/www/html/myproject/app/cache/dev/assetic/routing.yml").
官方页面这里有解决方法。他们说使用 LiipImageBundle。
http://symfony.com/doc/current/assetic/jpeg_optimize.html
Url 基于过滤器样本:
<img src="{{ asset('/relative/path/to/image.jpg') | imagine_filter('my_thumb') }}" />
<img src="{{ asset("assets/img/sample.jpg") }}"/>
我想使用 sample.jpg
和过滤器
{% image "assets/img/sample.jpg" filter="jpegoptim" %}
<img src"{{ asset_url }}"/>
{% endimage %}
这里应有尽有
但我想从变量中获取文件。像这样:
{% set image = "sample.jpg" %}
{% image "assets/img/"~image filter="jpegoptim" %}
<img src="{{ asset_url }}"/>
{% endimage %}
错误:
Unexpected token "name" of value "image"
如果我在此配置下使用 twig jpegoptim 函数
#config.yml
assetic:
debug: '%kernel.debug%'
use_controller: '%kernel.debug%'
filters:
jpegoptim:
bin: /usr/bin/jpegoptim
strip_all: true
max: 80
twig:
functions:
jpegoptim: ~
模板文件:
<img src="{{ jpegoptim("assets/img/"~image) }}/>
错误:
Notice: Undefined index: jpegoptim in . (which is being imported from "/var/www/html/myproject/app/cache/dev/assetic/routing.yml").
官方页面这里有解决方法。他们说使用 LiipImageBundle。
http://symfony.com/doc/current/assetic/jpeg_optimize.html
Url 基于过滤器样本:
<img src="{{ asset('/relative/path/to/image.jpg') | imagine_filter('my_thumb') }}" />