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

      typedef

      Store a variable local to the template.

      • source

      *variable

      A placeholder for a value that is local to the template.

      <drivers-licenses {^selected}="*selectedDriver"/>
      <edit-driver {driver}="*selectedDriver"/>
      

      Use

      Every template contains a context which is able to store values local to the template. Keys with * reference variables in that context.

      Template variables are often used to pass data between components. <component-a> exports its propA value to the template variable *variable. This is, in turn, used to update the value of propB in <component-b>.

      <component-a {^prop-a}="*variable"/>
      <component-b {prop-b}="*variable"/>
      

      Template variables are global to the template. Similar to JavaScript var variables, template variables do not have block level scope. The following does not work:

      {{#each something}}
          <component-a {^prop-a}="*variable"/>
          <component-b {prop-b}="*variable"/>
      {{/each}}
      

      To work around this, an localContext helper could be created as follows:

      stache.regsiterHelper("localContext", function(options){
        return options.fn(new Map());
      });
      

      And used like:

      {{#each something}}
          {{#localContext}}
            <component-a {^prop-a}="./variable"/>
            <component-b {prop-b}="./variable"/>
          {{/localContext}}
      {{/each}}
      

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