Play 2.4 scala - Is pattern matching in templates no longer supported

251 views
Skip to first unread message

Toby Hobson

unread,
Jul 30, 2015, 12:22:48 PM7/30/15
to play-framework
I need to pattern match on an object in my template, basically I need to handle the rendering differently depending on whether i'm dealing with a base class or a sub class. The 2.0 docs show an example of such matching but I can't find anything in the 2.4 docs. Is this no longer supported and if so is there a workaround?

Thanks

Will Sargent

unread,
Jul 30, 2015, 2:58:56 PM7/30/15
to play-fr...@googlegroups.com
Can you provide a test case which fails?

On Thu, Jul 30, 2015 at 9:22 AM, Toby Hobson <toby....@gmail.com> wrote:
I need to pattern match on an object in my template, basically I need to handle the rendering differently depending on whether i'm dealing with a base class or a sub class. The 2.0 docs show an example of such matching but I can't find anything in the 2.4 docs. Is this no longer supported and if so is there a workaround?

Thanks

--
You received this message because you are subscribed to the Google Groups "play-framework" group.
To unsubscribe from this group and stop receiving emails from it, send an email to play-framewor...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/play-framework/2d7d7305-549d-4474-9ff1-c4b955aa645e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Toby Hobson

unread,
Jul 30, 2015, 3:33:13 PM7/30/15
to play-framework, will.s...@typesafe.com
Hi Will,

My question wasn't whether it works or not. I just wanted to know if the feature is still supported (either in the community or commercial sense) because it has been removed from the docs. Basically my team is writing a prototype using Play as part of a technoogy evalutation and we don't want to get half way into this, hit a problem and be told "that feature is no longer supported". In general I've seen quite a bit of inconsistency in the docs between versions and it's hard to know if it's because features have been deprecated/removed or someone simply forgot to add them.

bassebergman

unread,
Jul 31, 2015, 8:00:20 AM7/31/15
to play-framework, will.s...@typesafe.com, toby....@gmail.com
The Twirl template-language does use Scala which supports pattern matching.
check out this link where there still is an example of pattern matching on a string: https://playframework.com/documentation/2.4.x/ScalaTemplateUseCases#Tags-%28they-are-just-functions,-right?%29

Toby Hobson

unread,
Jul 31, 2015, 9:38:53 AM7/31/15
to play-framework, will.s...@typesafe.com, toby....@gmail.com, ba...@grafikfel.org
Thanks Sebastian, that's helpful. As I understand it whitespace is treated differently in twirl so for example this will not work:

@level match {
    case "success" => <p>success</p>
}

but this will:

@level match {
    case "success" => { <p>success</p> }
}

Is my understanding correct?
Reply all
Reply to author
Forward
0 new messages