Assetic(带有Symfony 2)在';assetic:转储';正在运行


Assetic (with Symfony 2) changes the name of image files when 'assetic:dump' is run

每当我运行命令php app/console assetic:dump时,我的所有资产(css、javascript、image)都会成功地放入web/文件夹中。我遇到的唯一问题是Assetic更改图像文件名,可能是为了破坏缓存,这会干扰我的css文件中引用的图像。

当我手动将图像放置在web/images/masthead-4.jpg中时,它会正确显示。如果可能的话,我想保持对图像的缓存破坏我更愿意让其中一个解决方案发挥作用:

  • 我在css规则中使用处理后的图像,例如

    .is--site_landing { background: transparent url('../images/d755b65-aa84794_masthead-4_1-86f4322.jpg') top center no-repeat; background-size: cover; }

  • 获取要从app/Resources/public/images传输到的图像web/images而不让Assetic更改文件名?

我的图像位于%kernel.root_dir%/app/Resources/public/images中。例如,假设我有一个文件%kernel.root_dir%/app/Resources/public/images/masthead-4.jpg


图像文件的php app/console assetic:dump的输出为:

20:22:40 [file+] /our_stuff/admin/symfony/app/../web/images/d755b65-aa84794.jpg
20:22:40 [file+] /our_stuff/admin/symfony/app/../web/images/d755b65-aa84794_masthead-4_1-86f4322.jpg

现在文件名为d755b65-aa84794_masthead-4_1-86f4322.jpgd755b65-aa84794.jpg,我的背景图像css规则找不到图像。


我的背景CSS规则位于%kernel.root_dir%/app/Resources/public/images

    .is--site_landing {
      background: transparent url('../images/masthead-4.jpg') top center no-repeat;
      background-size: cover;
    }

Twig布局文件中的标题:

{% stylesheets
  'css/style.css.scss'
  filter='cssrewrite'
%}
<link rel="stylesheet" href="{{ asset_url }}">
{% endstylesheets %}
{% javascripts
  'js/jquery-1.11.2.min.js'
%}
<script src="{{ asset_url }}"></script>
{% endjavascripts %}  
{%image 
  'images/masthead-4.jpg'
%}
{% endimage %}

更多信息:我正在运行:

  • PHP 5.3.3
  • Symfony 3.3
  • 资产束~2.3

资产用于处理资产。如果你不喜欢它来处理你的图像,就不要用它来处理图像。

首先,去掉它,你不需要它。

{%image 
  'images/masthead-4.jpg'
%}
{% endimage %}

接下来,使用php app/console assets:install --symlinkweb文件夹中创建符号链接。像这样,您的CSS文件可以访问图像文件。