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

      typedef

      A named reference to a value in the scope or helper scope in a template.

      • source

      key

      Looks up a value in the scope or helper scope. This results in a KeyLookup Expression. KeyLookup Expression expressions can provide different values depending on what type of expression they are within. These rules are detailed in KeyLookup Expression.

      {{name}}
      {{#canVote(age)}}
      

      EXPRESSION.key

      Looks up key on the result of a subexpression EXPRESSION.

      {{person.first.name}}
      {{#if tasks.completed().length}} ... {{/if}}
      

      a\\.single\\.key

      Looks up a value without reading intermediate properties.

      {{meta\\.data}}
      

      This is deprecated. If you do have properties with dots in them, use a Bracket Expression:

      {{["meta.data"]}}
      

      Use

      A key references a value within the scope of a template being rendered. In the following example, the key is name:

      <h1>{{name}}</h1>
      

      If this template is rendered with:

      {
        name: "Austin"
      }
      

      The template writes out:

      <h1>Austin</h1>
      

      A scope is a collection of multiple contexts. By default, a key walks up the scope to each context until it finds a value. For example, a template like:

      {{first}} {{last}}
        {{#children}}
          {{first}} {{last}}
        {{/children}}
      

      Rendered with:

      {
        first: "Barry", last: "Meyer",
        children: [
          {first: "Kim", last: "Sully"},
          {first: "Justin"},
        ]
      }
      

      Writes out:

      Barry Meyer
          Kim Sully
          Justin Meyer
      

      When last is looked up on the {first: "Justin"} object and not found, it will then try to read the parent context's last property. This is why "Justin Meyer" is written out.

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