Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Variables
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  3 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
RyanT  
View profile  
 More options Nov 6 2012, 6:52 am
From: RyanT <truongducth...@jayeson.com.sg>
Date: Tue, 6 Nov 2012 03:52:19 -0800 (PST)
Local: Tues, Nov 6 2012 6:52 am
Subject: [Play 2.0.4 - Template engine] Variables

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.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Discussion subject changed to "[Play 2.0.4 - Template engine] Variables" by Julien Richard-Foy
Julien Richard-Foy  
View profile  
 More options Nov 6 2012, 9:15 am
From: Julien Richard-Foy <j...@zenexity.com>
Date: Tue, 6 Nov 2012 15:15:43 +0100
Local: Tues, Nov 6 2012 9:15 am
Subject: Re: [play-framework] [Play 2.0.4 - Template engine] Variables

Hi, this has nothing to do with variables. In Scala if is an expression
(equivalent to the `?` of Java), so you can just write:

@inputText(
  …,
  args = '_label -> "Username", 'disabled -> if (action == "disable")
"disabled" else "enabled"
)

You could define an intermediate value for the result of the `if`, if you
want to:

@defining(if (action == "disable") "disabled" else "enabled") { disabled =>
  @InputText(
    …,
    args = '_label -> "Username", 'disabled -> disabled
  )

}

By the way comparing String values is a weak design, I would prefer to use
an enumeration or a sum type.

Regards,
Julien


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
RyanT  
View profile  
 More options Nov 6 2012, 10:43 pm
From: RyanT <truongducth...@jayeson.com.sg>
Date: Tue, 6 Nov 2012 19:43:48 -0800 (PST)
Local: Tues, Nov 6 2012 10:43 pm
Subject: Re: [play-framework] [Play 2.0.4 - Template engine] Variables

I guess I have to start looking in Scala language...

Thanks alot,


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »