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 ...

Get Play Framework Essentials now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.