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
  • /
  • {{#with expression}}
  • / On this page
    • {{#with expression}}

      function

      Changes the context within a block.

      • source

      {{#with EXPRESSION}}BLOCK{{/with}}

      Renders BLOCK with the result of EXPRESSION added to the top of the can-view-scope.

      {{#with person.address}}
          Street: {{street}}
          City: {{city}}
      {{/with}}
      

      Parameters

      1. EXPRESSION {KeyLookup Expression|Call Expression}:

        A lookup expression that will provide a value.

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

        A template that is rendered with the context of the EXPRESSION's value.

      Use

      {{#with}} renders a subsection with a new context added to the can-view-scope. For example:

      TEMPLATE:
          {{#with person.address}}
              Street: {{street}}
              City: {{city}}
          {{/with}}
      DATA:
          {person: {address: {street: "123 Evergreen", city: "Springfield"}}}
      
      RESULT:
          Street: 123 Evergreen
          City: Springfield
      

      The difference between {{#with}} and the default {{#expression}} is that the subsection BLOCK is rendered no matter what:

      TEMPLATE:
          {{#with person.address}}
              Street: {{street}}
              City: {{city}}
          {{/with}}
      DATA:
          {person: {}}
      
      RESULT:
          Street:
          City:
      

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