Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Partial views in Play exist?

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?

like image 851
Incerteza Avatar asked Jan 06 '14 03:01

Incerteza


1 Answers

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.

like image 169
James Roper Avatar answered Sep 23 '22 01:09

James Roper