0

Situation: I have to place many scripts in "javascripts" native twig block.

- 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() :'' )}" )

How to put scripts each in particular line?

Example:

- 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() :'' )}" )

Error:

An exception has been thrown during the compilation of a template ("Illegal nesting: nesting within interpolated string is illegal in ... bla bla bla ... layout.html.haml".

Please don't offer assets/js/*

Nicolai Fröhlich
  • 51,330
  • 11
  • 126
  • 130
ZloyPotroh
  • 377
  • 7
  • 20

1 Answers1

1

Quick and easy: Define your asset collections in config.yml (or an assetic.yml file that you import) instead of in the template:

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
                # ...

Then in your haml template:

 - javascripts '@js_collection_one' output="assets/js/all.js"
     %script( type="text/javascript" src="#{asset_url~(app.environment == 'dev' ? '?'~random() :'' )}" ) 
Nicolai Fröhlich
  • 51,330
  • 11
  • 126
  • 130