{{#switch expr}}

  • function

{{#switch expr}}BLOCK{{/switch}}

Renders the BLOCK with contextual {{#case expr}} and {{#default}} helpers.


  1. expr {can.stache.expression}

    An expression or key that references a value that will be switched on.

  2. BLOCK {can.stache(template)}

    a template that is rendered, uses {{#case expr}} and {{#default}} helpers to match expr.



A fragment containing the rendered BLOCK.

The switch helper is used to render a block where one of several cases matches expr. It works just like a JavaScript switch.

{{#switch page}}

    {{#case "cart"}}
        <can-import from="cart">

        <can-import from="home">