Scala templating in Play

Play supports the use of Scala code within views and also provides a couple of helper methods to ease the process of defining a view.

We've created different views till now. Let's see how they are actually rendered. Consider the view for the Task Tracker app we saw in Chapter 1, Getting Started with Play.

@(tasks: List[Task], taskForm: Form[String]) @import helper._ @main("Task Tracker") { <h2>Task Tracker</h2> <div> @form(routes.TaskController.newTask) { @taskForm.globalError.map { error => <p class="error"> @error.message </p> } <form> <input type="text" name="taskName" placeholder="Add a new Task" required> <input type="submit" value="Add"> </form> } </div> <div> <ul> @tasks.map { task => <li> @form(routes.TaskController.deleteTask(task.id)) ...

Get Mastering Play Framework for Scala 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.