Reputation: 4485
I need to make a quick change to a page built in Scala in a Play app. Not really sure how to do this...
I have a variable @name that contains "foo" and I want to do this:
<div id="@name" class="@name_class">
and have it resolve to
<div id="foo" class="foo_class">
however Play is trying to look for a variable named @name_class
Upvotes: 1
Views: 343
Reputation: 2256
You can enclose with parenthesis, I haven't really tested with curly braces.
<div id="@name" class="@(name)_class"> ...
Upvotes: 0
Reputation: 955
You can first concatenate the string and the display:
@val class_name = name + "_class"
And then assign:
<div id="@name" class="@class_name">
EDIT
As explained in the comment by @Chirlo the above will not work as of Play 2.1 you can put concatenation in a reusable block and use as such:
@mkClassString(name:String,tag:String):String = { name + tag }
and use it:
<div id="@name" class="@mkClassString(name,"_class")">
or use @defining
as indicated by comment.
Upvotes: 0
Reputation: 26210
You can avoid a temporary variable with the following:
<div id="@name" class="@{name}_class"> ...
Upvotes: 17