twirl icon indicating copy to clipboard operation
twirl copied to clipboard

Support for else if

Open benmccann opened this issue 12 years ago • 26 comments

@marcusatbang @adis-me @npcode @xuwei-k asked for else if in https://github.com/playframework/playframework/issues/1376 and I'm moving the issue here

It would be nice to write something like this in the views:

@if(something) {
  ...
} else if (somethingElse) {
  ...
} else {
  ...
}

At present you have to nest if/else statements or use a match/case statement.

benmccann avatar Jun 16 '14 02:06 benmccann

And what about?

@fooSeq.map { foo =>
    ...
} else {
    ...
}

instead of:

@if(!fooSeq.isEmpty) {
    @fooSeq.map { foo =>
        …
    }
} else {
    ...
}

And this:

@fooOption.map { foo =>
    ...
} else {
    ...
}

instead of:

@fooOption.map { foo =>
    ...
}.getOrElse {
    ...
}

I know it is not a huge necessity, but it would be more readable.

adrianhurt avatar Sep 16 '14 21:09 adrianhurt

@adrianhurt

implicit class OptionOps[T](a: Option[T]) {
  def `else`[R >: T](body: => R) = {
    a.getOrElse(body)
  }
}

MasseGuillaume avatar Oct 31 '14 17:10 MasseGuillaume

+1000

kflorence avatar Jan 28 '15 00:01 kflorence

+1

manub avatar Feb 06 '15 15:02 manub

+1

anand-singh avatar Feb 06 '15 19:02 anand-singh

+1

mkurz avatar Feb 06 '15 19:02 mkurz

+1

georgeOsdDev avatar Mar 20 '15 03:03 georgeOsdDev

+1

nairouz avatar Apr 10 '15 20:04 nairouz

+1

wangjuns avatar May 11 '15 06:05 wangjuns

+1

blast-hardcheese avatar Jun 01 '15 22:06 blast-hardcheese

+1

slorber avatar Aug 18 '15 14:08 slorber

+1

jjudd avatar Sep 02 '15 16:09 jjudd

+1

pisfly avatar Oct 18 '15 14:10 pisfly

+1

giuseppedicarlo avatar Nov 07 '15 10:11 giuseppedicarlo

+1

dgouyette avatar Nov 24 '15 13:11 dgouyette

+1

maxaudrin avatar Nov 24 '15 14:11 maxaudrin

+1

4x4notfound avatar Dec 04 '15 13:12 4x4notfound

Has this been implemented yet? Just curious?

ddavisgraphics avatar May 24 '16 15:05 ddavisgraphics

This has not been implemented.

wsargent avatar May 24 '16 17:05 wsargent

@wsargent Thanks.

ddavisgraphics avatar May 24 '16 17:05 ddavisgraphics