{{#switch expr}}

  • function
can.stache.helpers.switch  

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

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

Parameters

  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.

Returns

{DocumentFragment}

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">
            <cart-page></cart-page>
        </can-import>
    {{/case}}

    {{#default}}
        <can-import from="home">
            <home-page></home-page>
        </can-import>
    {{/default}}

{{/switch}}