I am trying to learn Play 2.0 using scala, but I don’t think I understand how the template system for game 2.0 works. I have used game 1.2 before, and I'm kind of looking for the equivalent of # {include 'views / blah.html' /}. I really want to create a navigation bar that appears on all 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 href=@routes.Application.tasks >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 href=@routes.Application.tasks >Tasks</a> </li> </ul> } { task code }
Now, to enable this navigation bar, it seems to me that I have to repeat this on every page in such a way, I will have to hardcode this navigation bar on each page. Is there a way to do this without writing the entire navigation bar on each page?
I also tried creating a navbar.scala.html file containing
<h1>Index</h1> <ul> <li> <a href=@routes.Application.tasks >Tasks</a> </li> </ul>
and saving to the view / then importing using @import views.navbar
, but then I get the error message “navbar is not a member of the views”. I write this in the Eclipse Java EE Indigo IDE if this helps.
Darbs source share