我在此问题上进行了一些测试,并进行了两次可能的tw。
<!-- standard syntax: -->
{% image img/promo/widget.autopromo.testimonial.jpg filter= jpegoptim output= img/*.js %}
<img src="{{ asset_url }}" alt="Example"/>
{% endimage %}
<!-- twig function: -->
<img src="{{ jpegoptim( img/promo/widget.autopromo.activity.jpg ) }}" />
我从以下组合开始:
assetic:
debug: %kernel.debug%
use_controller: %kernel.debug%
read_from: %kernel.root_dir%/../web/static/
write_to: %kernel.root_dir%/../web/static/optimasset
filters:
jpegoptim:
bin: /usr/bin/jpegoptim
apply_to: ".jpe?g$"
strip_all: true
twig:
functions:
jpegoptim: ~
二. 变化 我拥有以下指挥权,以确保海滩清晰,新的档案被倾倒。
rm -Rvf app/cache/* # yes I wanted to make that sure cache is cleared
rm -Rvf web/static/optimasset;
app/console cache:clear --no-warmup;
app/console assetic:dump
www.un.org/Depts/DGACM/index_spanish.htm
00 First the dump output was
web/static/optimasset/images/e749c9f.jpg
web/static/optimasset/images/e749c9f_widget.autopromo.testimonial_1.jpg
web/static/optimasset/assetic
web/static/optimasset/assetic/bb69582.jpg
web/static/optimasset/assetic/bb69582_widget.autopromo.activity_1.jpg
和生成
<img src="/static/images/e749c9f_widget.autopromo.testimonial_1.jpg" alt="Example">
<img src="/static/assetic/c03bc54.jpg">
Note:
- the twig function generates a wrong filename.
- Both consider the
write_to
parameter in config.yml when dumping assets but still create a default folder (assetic/
or images
).
- Both ignore the
write_to
parameter when generating html but use their default folder following the folder specified in framework.templating.assets_base_urls.http
- Twig function generate html with a wrong filename
www.un.org/Depts/DGACM/index_spanish.htm
<>0> Specting an输出目录 in the config.yml
filters:
jpegoptim:
bin: /usr/bin/jpegoptim
apply_to: ".jpe?g$"
strip_all: true
output: img/*.jpg # just a test
twig:
functions:
jpegoptim: {output: img/*.jpg } # according to documentation
<>说明: 你的代价完全相同。 两个辛迪加都不处理“产出”问题(只是tw)。
www.un.org/Depts/DGACM/index_spanish.htm
<>0> 具体产出:
我在产出道路上添加了<代码>optimasset/,因为这样就不考虑````'write_to''价值。
{% image img/promo/widget.autopromo.testimonial.jpg filter= jpegoptim output= optimasset/img/*.jpg %}
<img src="{{ asset_url }}" alt="Example"/>
{% endimage %}
<img src="{{ jpegoptim( img/promo/widget.autopromo.activity.jpg , {output: optimasset/img/*.jpg }) }}" />
倾销:
web/static/optimasset/optimasset/img
web/static/optimasset/optimasset/img/974c414.jpg
web/static/optimasset/optimasset/img/974c414_widget.autopromo.testimonial_1.jpg
web/static/optimasset/optimasset/img/c230e9e.jpg
web/static/optimasset/optimasset/img/c230e9e_widget.autopromo.activity_1.jpg
成为:
<img src="/static/optimasset/img/974c414_widget.autopromo.testimonial_1.jpg" alt="Example">
<img src="/static/optimasset/img/080b62e.jpg">
Note: The rendering is correct but the dumping path is not. To fix this I had to remove the write_to
parameter.
www.un.org/Depts/DGACM/index_spanish.htm
CONCLUSION
{{ optipng(...) }}
as {{ jpegoptim(...) }}
never output the good file name.
Use the syntax {% images ... %}
.
- You should nt use
write_to
if you are using assetic to filter images {% images %} doesn t consider it when rendering html, only {% javascripts %}
and {% stylesheets %}
do.