with (options) Stringpublic
Use the {{with}} helper when you want to alias a property to a new name. This is helpful for semantic clarity as it allows you to retain default scope or to reference a property from another {{with}} block.
If the aliased property is "falsey", for example: false, undefined null, "", 0, NaN or an empty array, the block will not be rendered.
{{! Will only render if user.posts contains items}}
{{#with user.posts as |blogPosts|}}
<div class="notice">
There are {{blogPosts.length}} blog posts written by {{user.name}}.
</div>
{{#each blogPosts as |post|}}
<li>{{post.title}}</li>
{{/each}}
{{/with}}
Without the as operator, it would be impossible to reference user.name in the example above.
NOTE: The alias should not reuse a name from the bound property path. For example: {{#with foo.bar as |foo|}} is not supported because it attempts to alias using the first part of the property path, foo. Instead, use {{#with foo.bar as |baz|}}.
Parameters:
-
options
Object
Returns:
-
String - HTML string
Please login to continue.