Symfony2 mthaml语法

时间:2013-11-19 13:07:30

标签: javascript symfony haml mthaml

情况: 我必须在“javascripts”原生树枝块中放置许多脚本。

- javascripts 'assets/js/jquery.js' 'assets/js/some1.coffee' 'assets/js/some2.coffee' ...  'assets/js/someN.coffee' output="assets/js/all.js"
    %script( type="text/javascript" src="#{asset_url~(app.environment == 'dev' ? '?'~random() :'' )}" )

如何将每个脚本放在特定的行中?

示例:

- javascripts 'assets/js/jquery.js' 
'assets/js/some1.coffee' 
'assets/js/some2.coffee' ...  
'assets/js/someN.coffee' 
output="assets/js/all.js"
    %script( type="text/javascript" src="#{asset_url~(app.environment == 'dev' ? '?'~random() :'' )}" )

错误:

  

在编译模板期间抛出了异常   (“非法嵌套:在插值字符串中嵌套是非法的   ... bla bla bla ... layout.html.haml“。

请不要提供assets/js/*

1 个答案:

答案 0 :(得分:1)

快速简便:在config.yml(或您导入的assetic.yml文件中)而不是在模板中定义资产集合:

assetic:
    assets:
        # An array of named assets (e.g. some_asset, some_other_asset)
        js_collection_one:
            inputs: 
                - assets/js/some1.coffee
                - assets/js/some2.coffee
                # ...

然后在你的haml模板中:

 - javascripts '@js_collection_one' output="assets/js/all.js"
     %script( type="text/javascript" src="#{asset_url~(app.environment == 'dev' ? '?'~random() :'' )}" )