2013-05-22 36 views
2

我在我的軟件包Resources中包含一個名爲vendor的目錄,其中包含JavaScript庫等。其中一些供應商包含圖像。在網絡目錄中安裝供應商資源

我可以用資產導入CSS /少/ js文件:

assetic: 
    assets: 
     flot: 
      inputs: 
       - @MyBundle/Resources/vendor/flot/jquery.flot.js 
       - @MyBundle/Resources/vendor/flot/jquery.flot.time.js 
      filters: 
       - ?yui_js 

但是,如果供應商包含圖像,我不知道,如何把它們放進web/目錄。

我寧願不手動將它們符號鏈接。

回答

3

Assetic的喜歡

assetic: 
    assets: 
     collection_name: 
      inputs: 
       - ... 
      output: 
       - desired_filename # relative to assetic.output_path 
      filters: 
       - ?lessphp   # scss, optipng, jpegoptim ... whatever 
            # the ? (question mark) prevents the 
            # filter to be applied in dev mode 

資源集合還可以包含圖像。但你必須通過一個

assetic: 
    assets: 

     [...] 

     my_image: 
      inputs: 
       - /path/to/image/image.png 
      output: 
       - images/smushed_image.png 
      filters: 
       - optipng  

     my__second_image: 
      inputs: 
       - /path/to/image/image2.jpg 
      output: 
       - images/smushed_image2.jpg 
      filters: 
       - jpegoptim  

指定它們一個接着用assetic:轉儲命令讓他們寫(並編譯/ smushed)到您的Web文件夾。 --no-debug選項可防止資產爲每個包中的每個文件創建調試文件。用於生產系統,或者如果您有調試的另一種方式(即真棒Source Maps

app/console assetic:dump --no-debug 

使用包這樣的:

{% stylesheets '@collection_name' %} 
    <link rel="stylesheet" type="text/css" href="{{ asset_url }}" /> 
{% endstylesheets %} 

{% image '@my_image' %} 
    <img src="{{ asset_url }}" alt="Example"/> 
{% endimage %}