Skip to content

Add a {#switch} block #13507

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

Description

@Ocean-OS

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

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