How To Pass A Script To Main.scala.html - Play! 2
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: @(title: String,moreScripts: Html)(content: Html
Solution 1:
This has been discussed on the mailing list. Hope that helps.
@main{ <scriptsrc="javascripts/test/test.js"type="text/javascript"></script> } {
<h1>Test</h1>
}
Solution 2:
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 = { <scriptsrc="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
Post a Comment for "How To Pass A Script To Main.scala.html - Play! 2"