How to pass a script to main.scala.html - Play! 2

前端 未结 2 1624
清酒与你
清酒与你 2021-01-22 11:16

I am trying to pass javascripts specific to a page as a parameter to the main template. This is what I have tried:

main.scala.html:

@(ti         


        
相关标签:
2条回答
  • 2021-01-22 11:57

    I struggled with this as well, but this seemed to work for me:

    main.scala.html:

    @(title: String, moreScripts: Html = Html(""))(content: Html)
    <!DOCTYPE html>
    <html>
      <head>
       <title>@title</title>
       @moreScripts
      </head>
      <body>
       @content
      </body>
    </html>
    

    test.scala.html:

    @moreScripts = { <script src="routes.Assets.at("javascripts/MyJS.js")"></script>}
    
    @main("Page Title", moreScripts) {
      <h1>Some content here</h1>
    }
    

    Of course, your Javascript file should be located at app/assets/javascripts as either a standard Javascript or Coffeescript file

    0 讨论(0)
  • 2021-01-22 12:11

    This has been discussed on the mailing list. Hope that helps.

    @main{ <script src="javascripts/test/test.js" type="text/javascript"></script> } {
       <h1>Test</h1>
    }
    
    0 讨论(0)
提交回复
热议问题