我想學習與斯卡拉播放2.0,但我不認爲我很理解如何2.0模板系統的作品。我之前使用過Play 1.2,我正在尋找與#{include'views/blah.html'/}等效的內容。我基本上想要創建一個在所有頁面上呈現的導航欄。包括scala.html文件在播放2.0斯卡拉
基本上main.scala.html我有
@(title: String)(navbar: 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>
</head>
<header>
This is my header
</header>
<section class="navbar">@navbar</section>
<section class="content">@content</section>
<footer>
This is my footer
</footer>
,並在我的index.scala.html:
@navbar = {
<h1>Index</h1>
<ul>
<li>
<a [email protected]>Tasks</a>
</li>
</ul>
}
@main("Home")(navbar){
content
}
在task.scala.html
:
@(tasks: List[Task], taskForm: Form[String])
@import helper._
@main("Home") {
<h1>Index</h1>
<ul>
<li>
<a [email protected]>Tasks</a>
</li>
</ul>
} {
task code
}
現在包括這個na VBB似乎我必須在每一頁這樣重複這一點,我將不得不將這個導航欄硬編碼到每一頁。有沒有辦法做到這一點,而無需在每個頁面中編寫整個導航欄?
我也試圖創建一個包含
<h1>Index</h1>
<ul>
<li>
<a [email protected]>Tasks</a>
</li>
</ul>
一個navbar.scala.html文件,並根據意見節省/然後導入,使用@import views.navbar
但後來我得到一個錯誤,說明「導航欄不是意見的成員」。如果有幫助,我在Eclipse Java EE IDE indigo中編寫它。
:BaseScalaTemplate([email protected]),而不是實際的navbar.scala.html – Darbs
你能告訴我們你的代碼? – Somatik
哦,是的,你可能需要添加parens。我編輯了我的答案。 –