0

I'm learning Play and I met the following problem : I want to display the elements of my list in a Scala template. From this post, I saw that I can use the function map on the list but in my case, instead to show the contents of the properties, it shows that :

@product.description
@product.name
@product.description
@product.name
@product.description
@product.name
@product.description
@product.name
@product.description 

Product.scala

package models

case class Product(ean : Long, name : String, description : String)

object Product {
  var products = Set(
    Product(5010255079763L, "Paperclips Large", "Large Plain Pack of 1000"),
    Product(5018206244666L, "Giant Paperclips", "Giant Plain 51mm 100 pack"),
    Product(5018306332812L, "Paperclip Giant Plain", "Giant Plain Pack of 10000"),
    Product(5018306312913L, "No Tear Paper Clip", "No Tear Extra Large Pack of 1000"),
    Product(5018206244611L, "Zebra Paperclips", "Zebra Length 28mm Assorted 150 Pack")
  )

  def findAll = products.toList.sortBy(_.ean)
}

Here how I display the elements :

@(products : List[Product])(implicit lang : Lang)

@main(Messages("application.name")) {
<dl class="products">
  <!-- This is working -->
  <!-- @for(product <- products) { -->
  <!-- <dt>@product.name</dt> -->
  <!-- <dd>@product.description</dd> -->
  <!-- } -->
  @products.map(product =>
    <dt>@product.name</dt>
    <dd>@product.description</dd>)
</dl>
}

Why the for expression is working and not the map like I want ?

Community
  • 1
  • 1
alifirat
  • 2,899
  • 1
  • 17
  • 33

1 Answers1

1

Curly brackets should be used instead parentheses when you have multiline expression

@products.map{product =>
 <dt>@product.name</dt>
 <dd>@product.description</dd>
 }
grotrianster
  • 2,468
  • 14
  • 14