Hi all,
I have this simple view:
--------------------------------------------------------------------------- --------------------------------
@(configureUserAcctForm: Form[forms.UserForm], action: String)
@import helper._
@main(title = "Configure an user account") {
@form(action = routes.Users.configure(action)) {
@inputText(
field = configureUserAcctForm("username"),
args = '_label -> "Username", *'disabled -> "disabled"*
)
<input type="submit" value="Save">
}
}
--------------------------------------------------------------------------- -----------
However I want to customize the code such that the disabled argument can be
set based on the value passed into the action parameter. I can think of a
way of doing this, as following:
--------------------------------------------------------------------------- ----------
@if (action.equals("dsiable")) {
@inputText(
field = configureUserAcctForm("username"),
args = '_label -> "Username", *'disabled -> "disabled"*
)
} else {
@inputText(
field = configureUserAcctForm("username"),
args = '_label -> "Username", *'disabled -> "enabled"*
)
}
--------------------------------------------------------------------------- --------------------------------------
however, with this way of doing result in a lot of code repetition (if we
have more fields, and/or multiple condition to check other than just the *
action* parameter).
I would prefer to do something like this
--------------------------------------------------------------------------- --------------------------------------
@xvalue = action.equals("disable")?"disabled":"enabled"
@inputText(
field = configureUserAcctForm("username"),
args = '_label -> "Username", *'disabled -> xvalue*
)
--------------------------------------------------------------------------- --------------------------------------
Is there anyway I could achieve this easily? I have done some googling and
found out that variables are not supported in the Play template engine (and
I wonder why?) Will variables be supported in future versions of the
template engine?
Thank you very much in advance.