O'Reilly logo

Play Framework Cookbook - Second Edition by Giancarlo Inductivo, Alexander Reelsen

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Using helper tags

View tags allow developers to create reusable view functions and components and make the management of views a lot simpler and easier.

How to do it...

For Java, we need to take the following steps:

  1. Run the foo_java application with Hot-Reloading enabled.
  2. Create the tag file productsIterator.scala.html in foo_java/app/views/tags
  3. Add the contents of the tag file:
        @(products: Collection[String])
    
        <ul>
          @for(product <- products) {
            <li>@product</li>
          }
        </ul>
  4. Edit foo_java/app/views/products.scala.html by adding the following block:
        @import tags._
     
        @productsIterator(products)
  5. Reload the products page using a web browser to see the new product listing, using an unordered list HTML tag:
    http://localhost:9000/products
    

For Scala, we need to take ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required