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
  • /
  • Helper Expression
  • / On this page
    • Helper Expression

      typedef
      • source

      method [EXPRESSION...]

      Calls method with zero or many arguments where each argument is a space separated EXPRESSION.

      {{method 1 key call() hashProp=hashValue}}
      

      Parameters

      1. EXPRESSION {Literal Expression|KeyLookup Expression|Hash Expression|Call Expression}:

        An expression that will be passed as an argument to method.

        All Hash Expressions will be collectively added to the helperOptions's hash object.

        If an EXPRESSION reads an observable, a compute will be passed to method.

      Use

      A helpers expression calls a function looked up in the helpers scope followed by the scope. It looks like:

      Template:
          <h1>{{pluralize type ages.length}}</h1>
      
      Data:
          {
            pluralize: function(type, count){
              return "data-pluralize"
            },
            todos: new List([22,32,42]),
            type: "age"
          }
      
      Helpers:
          {
            pluralize: function(type, count){
              return type+(count() === 1 ? "" : "s")
            }
          }
      
      Result:
          <h1>Ages</h1>
      

      Helper expression arguments that are observable are passed a compute. This is in contrast to Call expressions that get passed the value.

      Helper expression arguments are space seperated. If a Hash expression is an argument, the hash properties and values will be added to the helper options object. For example:

      Template:
          <h1>{{pluralize word=type count=ages.length}}</h1>
      
      Data:
          {
            todos: new List([22,32,42]),
            type: "age"
          }
      
      Helpers:
          {
            pluralize: function(helperOptions){
              return helperOptions.hash.type+(helperOptions.hash.count() === 1 ? "" : "s")
            }
          }
      
      Result:
          <h1>Ages</h1>
      

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