I haven't found any notion of partial views in Play Framework similar to Ruby on Rails's partial views. For example, if there is layouts/main.scala.html
layout:
@(title: String)(content: => Html)(implicit flash: Flash)
<!DOCTYPE html>
<html>
<head>
<title>@title</title>
</head>
<body>
<section class="content">@content</section>
</body>
</html>
And there is also layouts/_footer.scala.html
"partial", how do I include _footer
into main
?
Is there anything similar in Play?
I think RoR's partial views are overly complex. The thing to remember about Play templates, as that they are essentially just functions that can be called directly from Scala code. And also, Play templates are essentially Scala code. That means, Play templates can be called from other Play templates. So, just create another template called footer.scala.html
, eg:
<footer>
Powered by Play Framework
</footer>
And then call it from your main template, as you would invoke any other Scala function:
@(title: String)(content: => Html)(implicit flash: Flash)
<!DOCTYPE html>
<html>
<head>
<title>@title</title>
</head>
<body>
<section class="content">@content</section>
@footer()
</body>
</html>
Couldn't be easier.
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