Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Omitting "else" from an if statement #2002

Open
alshdavid opened this issue Apr 12, 2024 · 3 comments
Open

Omitting "else" from an if statement #2002

alshdavid opened this issue Apr 12, 2024 · 3 comments

Comments

@alshdavid
Copy link
Contributor

alshdavid commented Apr 12, 2024

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!

@casey
Copy link
Owner

casey commented May 15, 2024

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.

@chrass
Copy link

chrass commented May 22, 2024

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

@casey
Copy link
Owner

casey commented May 22, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants