Lilluda 5
Lilluda 5

Reputation: 1109

What does $ mean in a Scala Play Template, and how to deal with Options

First off, what exactly does $ mean in the Scala Play Template engine?

Second off, I am trying to deal with an type Option in my Scala Play template, and it seems what I am doing should be rather simple. Here is a snippet of code from my template.

@c = { Some(complication) } 
<div id="complication">
@Html( (@c.name getOrElse "") ) `  
</div> 

Where complication is of type Option[T]. The name field is of type string.

I've tried extracting it in to a another variable and then referencing the name field from that, but that seems so obtuse, there has to be a better solution it seems.

Upvotes: 1

Views: 323

Answers (1)

Michael Zajac
Michael Zajac

Reputation: 55569

With $ I think you may be referring to Scala's string interpolation.

Say you have val str: String = "hello", then s"$str world" is equivalent to str + " world"

You don't need the @ symbol inside @Html.

@Html( (c.name.getOrElse(""))) 

Upvotes: 2

Related Questions