DoneJS StealJS jQuery ++ FuncUnit DocumentJS
3.0.0
2.3.27

 

  • Github
  • Twitter
  • Chat
  • Forum
  • Guides
  • Core
    • can-component
    • can-compute
    • can-connect
    • can-define
    • can-define/list/list
    • can-define/map/map
    • can-route
    • can-route-pushstate
    • can-set
    • can-stache
      • Pages
        • Magic Tag Types
        • Scope and Context
        • Expressions
        • Template Acquisition
        • Helpers
        • Live Binding
      • Methods
        • from
        • registerConverter
        • registerHelper
        • registerPartial
        • registerSimpleHelper
        • safeString
      • Tags
        • {{expression}}
        • {{{expression}}}
        • {{#expression}}
        • {{/expression}}
        • {{^expression}}
        • {{>key}}
        • {{!expression}}
        • {{else}}
      • Expressions
        • Bracket Expression
        • Call Expression
        • Hash Expression
        • Helper Expression
        • KeyLookup Expression
        • Literal Expression
      • Key Operators
        • @at
        • ~compute
        • ./current
        • ../parent
        • %special
        • this
        • *variable
        • key
      • Helpers
        • {{#if expression}}
        • {{#unless expression}}
        • {{#each expression}}
        • {{#with expression}}
        • {{log}}
        • {{#is expressions}}
        • {{#switch expression}}
        • {{#case expression}}
        • {{#default}}
        • {{joinBase expressions}}
      • Types
        • getterSetter
        • helper
        • helperOptions
        • renderer
        • sectionRenderer
        • simpleHelper
    • can-stache/helpers/route
    • can-stache-bindings
  • Ecosystem
  • Infrastructure
  • Legacy
  • Bitovi
    • Bitovi.com
    • Blog
    • Consulting
    • Training
    • Open Source
  • Chat
  • Forum
  • Star
  • Follow @canjs
  • CanJS
  • /
  • Core
  • /
  • can-stache
  • /
  • {{#switch expression}}
  • / On this page
    • {{#switch expression}}

      function
      • source

      {{#switch EXPRESSION}}BLOCK{{/switch}}

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

      {{#switch user.type}}
          {{#case "admin"}}
              Pay
          {{/case}}
          {{#case "admin"}}
              <button/>
          {{/case}}
          {{#default}}
              Look at data
          {{/default}}
      {{/switch}}
      

      Parameters

      1. EXPRESSION {KeyLookup Expression|Call Expression}:

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

      2. BLOCK {sectionRenderer(context, helpers)}:

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

      Use

      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}}
      

      CanJS is part of DoneJS. Created and maintained by the core DoneJS team and Bitovi. Currently 3.0.0.