I'm don't know exactly how Apache Tiles works, but if I properly understand, it offers a way to create pages using smaller components (like header, menu, footer, etc) and some sort of include mechanism to glue these components together and then compose the page.
That said, you can achieve the same thing using Twirl. You just need to declare reusable blocks that can be used inside the same page, or you can have something like Rails partials that can be reused across different pages.
Let's see an example. Consider that you have the following files:
File app/views/partials/header.scala.html
:
<header>
<h1>My Header</h1>
</header>
File app/views/partials/navigation.scala.html
:
<nav>
<ul>
<li><a href="/home">Home</a></li>
<li><a href="/profile">Profile</a></li>
<li><a href="/faq">FAQ</a></li>
</ul>
</nav>
File app/views/partials/footer.scala.html
:
<footer>
Some copyright info
</footer>
File app/views/main.scala.html
:
@(title: String)(content: Html)
<!DOCTYPE html>
<html lang="en">
<head>
<title>@title</title>
<link rel="stylesheet" media="screen" href="@routes.Assets.versioned("stylesheets/main.css")">
<script src="@routes.Assets.versioned("javascripts/hello.js")" type="text/javascript"></script>
</head>
<body>
@partials.header()
@partials.navigation()
@content
@partials.footer()
</body>
</html>
The files above defines not only some reusable partial templates (header, navigation and footer), but also a common layout (main) that all the pages of your application can reuse. Now, lets see a page that uses the structure above:
File app/views/users/profile.scala.html
:
@(user: models.User)
@main(title = "User Profile Page") {
<h2>This is the profile page of @user.username</h2>
}
And there is more: since views are compiled to Scala code, you can import code written in Scala/Java and call it directly from your views, something like Rails view helpers:
File app/views/helpers/DateHelpers.scala
:
package views.helpers
object DateHelpers {
def formatToISO8601(date: Date) = {
??? // format the date
}
}
Let's use this helper in our app/views/users/profile.scala.html
page:
@(user: models.User)
@import controllers.DateHelpers._
@main(title = "User Profile Page") {
<h2>This is the profile page of @user.username.</h2>
<p>User since @formatToISO8601(user.createdAt)</p>
}
And there are other approaches to consider:
- Ping-Play: Big Pipe Streaming for the Play Framework
- You can create a Play module that integrate with Apache Tiles. I'm pretty sure this is possible.