-2

I'm trying to create a dynamic list of URLs in Twirl template with Play with no luck. I can't seem to map over a collection to create list of URLs for some reason. This is what I have:

@casesCollection.map(e => {
   <td><a href="/cases/@{e.get._id}/Search">@e.name</a></td>
})

The part within the href does not compile. Any ideas how this issue can be solved?

maloney
  • 1,633
  • 3
  • 26
  • 49

1 Answers1

0

You've not given enough details about the type of casesCollection and the error you're getting.

Here's a simplified example that works:

In the controller:

def index = Action {
    val casesCollection = List("A", "B", "C")
    Ok(views.html.xxx(casesCollection))
}

The view xxx.scala.html:

@(casesCollection: List[String])
<ul>
@casesCollection.map { e =>
    <li>@e</li>
}
</ul>

In my example casesCollection is a simple List of Strings. You may have a list of some sort of objects, but it should be easy to adapt.

Nick
  • 2,576
  • 1
  • 23
  • 44