Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Add a {#switch} block #13507

Copy link
Copy link
Closed as not planned
Closed as not planned
Copy link
@Ocean-OS

Description

@Ocean-OS
Issue body actions

Describe the problem

It is common to test a value to see what it is equal to, using multiple if/else blocks. However this can get tedious and repetitive quickly. Example:

{#if value === "Hi"}
Oh, hello!
{:else if value === "Bye"}
Goodbye!
{:else}
I don't understand...
{/if}

Describe the proposed solution

A {#switch } block would be useful. It would work like the JS switch block. Here's an example:

{#switch value break}
{:case "Hi"}
Oh, hello!
{:case "Bye"}
Goodbye!
{:default}
I don't understand...
{/switch}

The break part in the {#switch } block means that it breaks at the end of each {:case} block. If this is not in the switch block, a {:break} block can be used to break at the end of a case block. Here's a revision of the code above using {:break} blocks:

{#switch value}
{:case "Hi"}
Oh, hello!
{:break}
{:case "Bye"}
Goodbye!
{:break}
{:default}
I don't understand...
{/switch}

Importance

would make my life easier

Gorbulev-Sergey

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.