Book Image

Play Framework essentials

By : Julien Richard-Foy
Book Image

Play Framework essentials

By: Julien Richard-Foy

Overview of this book

This book targets Java and Scala developers who already have some experience in web development and who want to master Play framework quickly and efficiently. This book assumes you have a good level of knowledge and understanding of efficient Java and Scala code.
Table of Contents (9 chapters)
8
Index

Using the template engine to build web pages


For now, your Play application only handles JSON. To create data, you must supply a JSON payload with your HTTP request, and ensure the presentation of your application resources is only JSON. This can be sufficient if you just want to provide a web service. However, you sometimes also want to expose your resources as HTML pages so that users can browse them from their web browser.

Play includes a template engine, Twirl, that makes it easier to define skeleton HTML pages filled with data from your application and combine document fragments.

The app/views/main.scala.html file contains the HTML template used by the provided controllers.Application.index action. Have a look at it in your code editor. It contains a simple HTML document. The Application.index action renders it using the views.html.main() method (or views.html.main.render() in Java). You might ask how is the app/views/main.scala.html file related to the views.html.main object? The Play...