Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Variable in attribute value of XML-literal

Tags:

xml

scala

lift

I'm working with LiftWeb, XML and the bind method.

This works:

scala> val id = "test"                    
id: java.lang.String = test

scala> <a href={id}>link</a>              
res4: scala.xml.Elem = <a href="test">link</a>

but what if I want <a href="page?param=test">link</a>?

This doesn't work:

scala> <a href="page?param={id}">link</a>   
res5: scala.xml.Elem = <a href="page?param={id}">link</a>
like image 211
aioobe Avatar asked Jun 23 '11 07:06

aioobe


2 Answers

You put the whole thing inside the brackets:

<a href={ "page?param=" + id }>link</a>
like image 63
Knut Arne Vedaa Avatar answered Nov 06 '22 15:11

Knut Arne Vedaa


The answer to put it all in curly braces is correct. But don't forget that you need to have a string in the curly braces!

So, you have to write something like (not your example, obviously)

<edge label={name} weight={weight.toString} />

If you come from a language which converts types for you, it can cost you a few minutes of head scratching before you remember what's wrong, because SBT offers no error message, just underlines it.

like image 2
rumtscho Avatar answered Nov 06 '22 15:11

rumtscho