如何将脚本传递给 main.scala.html - 玩!2 [英] How to pass a script to main.scala.html - Play! 2
本文介绍了如何将脚本传递给 main.scala.html - 玩!2的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图将特定于页面的 javascripts 作为参数传递给主模板.这是我尝试过的:
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)
<!DOCTYPE html>
<html>
<head>
<title>@title</title>
<link rel="stylesheet" media="screen" href="@routes.Assets.at("stylesheets/main.css")">
<link rel="shortcut icon" type="image/png" href="@routes.Assets.at("images/favicon.png")">
<script src="@routes.Assets.at("javascripts/jquery-1.7.1.min.js")" type="text/javascript"></script>
@moreScripts
</head>
<body>
@content
</body>
</html>
test.scala.html:
@main("Test",<script src="javascripts/test/test.js" type="text/javascript"></script>) {
<h1>Test</h1>
}
但是我遇到了 类型不匹配的问题;发现:scala.xml.Elem 需要:play.api.templates.Html
错误.我还尝试将 语句包装在
@{}
中,但无济于事.
But I am getting an type mismatch; found : scala.xml.Elem required: play.api.templates.Html
error. I also tried wrapping the <script>
statement in @{}
to no avail.
我需要如何构造 语句,以便将语句识别为 HTML?
How do I need to structure the <script>
statement so that it is recognises the statement as HTML?
推荐答案
这已经在 邮件列表.希望有所帮助.
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>
}
这篇关于如何将脚本传递给 main.scala.html - 玩!2的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文