just icon indicating copy to clipboard operation
just copied to clipboard

Omitting "else" from an if statement

Open alshdavid opened this issue 1 year ago • 3 comments

Hi all,

Please close this issue if this is already possible - it doesn't seem to work currently

When using an if statement, an else block must be present

foo myarg:
  echo {{ if myarg != "" { "myarg is present" } else { "" } }}

Would it be possible to default to "" is an else block is omitted?

foo myarg:
  echo {{ if myarg != "" { "myarg is present" } }}

Thanks!

alshdavid avatar Apr 12 '24 22:04 alshdavid

I think this is probably reasonable. I don't really like defaulting to "", it just seems inelegant, but I don't see a better alternative.

casey avatar May 15 '24 02:05 casey

I'm taking a look at this issue because it looks relatively simple to implement, where exactly is the implementation for conditionals?

chrass avatar May 22 '24 20:05 chrass

It's in a few places, but you can start with Parser::parse_conditional, and make Expression::Conditional::otherwise an Option.

casey avatar May 22 '24 21:05 casey