Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Scala XML: brace escapes in attributes

Tags:

xml

scala

I'm fiddling around with scala's XML capabilities, trying to produce some xhtml form. Here's what I got:

class LoginForm {
    var title = "Login"
    var username = ""
    def content =
        <div class="login">
            <h1>{this.title}</h1>
            <input type="text" name="username" value="{this.username}" />
        </div>
}
var f = new LoginForm
f.username = "foo"
f.content

When the code is run, the title is interpolated as expected, but the value of the input element is not. Why is this? And is there a way around that problem?

like image 838
Dave Vogt Avatar asked Jul 09 '11 22:07

Dave Vogt


1 Answers

Okay, figured this one out by myself. The attribute quotes are added by scala itself, so we don't have to. So, the correct way would be this (note the missing quotes around the username interpolation):

<input type="text" name="username" value={this.username} />
like image 65
Dave Vogt Avatar answered Oct 29 '22 08:10

Dave Vogt