{{#with expression}}
function
Changes the context within a block.
{{#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
- EXPRESSION
{KeyLookup Expression|Call Expression}:A lookup expression that will provide a value.
- 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: