Reputation: 7919
I am using play framework for Java and working on a job portal project which contains the main site and with an admin panel. The main site and admin panel have different header and footer so I can't specify the header and footer in main as this would then be common for main site and admin panel.
So my main.scala.html looks like
@(title: String)(content: Html)
<html>
<head>
<title>Job Portal</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.9.0.min.js")" type="text/javascript"></script>
</head>
<body >
@content
</body>
</html>
Which contains only the content part.
I want to include header and footer (created in different static files) for main site in index.html. How can I do so in play framework for Java?
Is there any other approach which can solve my problem?
Upvotes: 2
Views: 307
Reputation: 14401
Lets assume that all your templates are located in the views directory.
Create another template, for example footer.scala.html with your desired content
footer.scala.html
@()
<div>This is foooter!</div>
Then in your main.scala.html you can include it by putting this line of code in it:
@views.html.footer()
The same goes with header or whatever you fancy.
This is referenced in docs as Includes (you can use also tags if you prefer), also keep in mind that you can pass parameters into included views/tags
Upvotes: 2