Skip to content

Use hash keys instead of an object in {{#with}}

Choose a tag to compare

@bmomberger-bitovi bmomberger-bitovi released this 21 Sep 17:55
· 756 commits to master since this release

The {{#with}} helper adds a new scope context (becoming the current this) and renders the subsection it contains. Prior to 3.8.0, the semantics for {{#with}} involved choosing an object on the scope to become this new context.

{{#with scopeObject}}
  <span>{{./propertyOnScopeObject}}</span>
{{/with}}

With 3.8.0, you now have the option to construct your own context object using hash expressions.

{{#with key=scopeLookup key2=anotherLookup}}
   <span>{{./key}}: {{key2}}</span>
{{/with}}

In addition, the behavior of {{#with}} with a context object was incorrect with respect to the documented behavior. Prior to 3.8.0, the subsection inside {{#with}}...{{/with}} would not render if passed a falsy object (the same behavior as creating a section with {{#}}). This was not the intended or documented behavior and has been fixed. Now the subsection always renders.

Note: this feature and behavior fix were added in version 3.7.3, which has now been deprecated in favor of this minor release due to the documented new feature.