I am trying to learn Play 2.0 with scala but I dont think i quite understand how the template system for play 2.0 works. I have used play 1.2 before and i am sort of looking for an equivalent to the #{include 'views/blah.html' /}. I essentially want to create a navbar that is rendered on all the pages.
Essentially in main.scala.html i have
@(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>
and in my index.scala.html:
@navbar = {
<h1>Index</h1>
<ul>
<li>
<a [email protected]>Tasks</a>
</li>
</ul>
}
@main("Home")(navbar){
content
}
in 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
}
Now to include this navbar it seems i have to repeat this in every page this way i would have to hard code this navbar into every page. Is there a way to do this without without writing the whole navbar in every page?
I have also tried creating a navbar.scala.html file that contains
<h1>Index</h1>
<ul>
<li>
<a [email protected]>Tasks</a>
</li>
</ul>
and saving under views/ then importing that using @import views.navbar
but then i get an error stating 'navbar is not a member of views'. I am writing this in Eclipse Java EE IDE indigo if that helps.
Dont import it but just call it:
@navbar()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With