CHAPTER 8: Play with Java and Scala 377
Listing 8-11. Simple Template
@(books: List[Book])
- @book.getTitle()
@for(book <- books) {
}
You can then call this from any Java code like you would normally call a method on a class.
Content html = views.html.Application.index.render(books);
Listing 8-12 illustrates the code for the index.scala.html template that you will find in the
app/views folder.
Listing 8-12. index.scala.html
- @(books: List[Book], bookForm: Form[Book])
- @import helper._
- @main("books") {
@books.size() book(s)
- @for(book <- books) {
- @book.label
- @form(routes.Application.deleteBook(book.id)) {
- }
- }
Add a new book
- @form(routes.Application.newBook()) {
- @inputText(bookForm("label"))
- }
- }