Adrian
Adrian

Reputation: 5681

Scala/Lift - map function

I'm using Lift to generate my web front. In the scala file I have a list: val testList = List("part1","part2","part3")
I'm apply a function to each element for the list. For now I just want to make them bold. I know there is another way to make them bold by changing the html code, but that's not the point of this exercise. I'm trying to see if I can generate the html in the scala file as opposed to the .html file.

I defined a function

 def formatText(s:String)={
    <B> s </B>
  }

and I call var testList2= testList.map(formatText(_))

The problem is that in the output all I see is s s s in bold. If I put quotes around the <B> then the string is escapsed so instead of getting part1 (in bold), I get < B >part1< / B >.

How do I display those strings in bold? Is there a $s to tell Lift/scala I mean the variable s and no char s in formatText?

Upvotes: 1

Views: 394

Answers (1)

DaoWen
DaoWen

Reputation: 33019

The XML-literal "escape" characters (for adding variables, expressions, etc) are { and }:

def formatText(s:String)= <B> {s} </B>

Take a look at Programming in Scala 26.3: XML Literals for more details.

Upvotes: 2

Related Questions