Skip to content

Latest commit

 

History

History
74 lines (60 loc) · 1.68 KB

File metadata and controls

74 lines (60 loc) · 1.68 KB

ember/template-no-with

HBS Only: This rule applies to classic .hbs template files only (loose mode). It is not relevant for gjs/gts files (strict mode), where these patterns cannot occur.

The use of {{with}} has been deprecated, you should replace it with either {{let}} or a combination of {{let}}, {{if}} and {{else}}.

Examples

This rule forbids the following:

<template>
  {{#with (hash name="Ben" age=4) as |person|}}
    Hi {{person.name}}, you are {{person.age}} years old.
  {{/with}}
</template>
<template>
  {{#with user.posts as |blogPosts|}}
    There are {{blogPosts.length}} blog posts.
  {{/with}}
</template>
<template>
  {{#with user.posts as |blogPosts|}}
    There are {{blogPosts.length}} blog posts.
  {{else}}
    There are no blog posts.
  {{/with}}
</template>

This rule allows the following:

<template>
  {{#let (hash name="Ben" age=4) as |person|}}
    Hi {{person.name}}, you are {{person.age}} years old.
  {{/let}}
</template>
<template>
  {{#let user.posts as |blogPosts|}}
    {{#if blogPosts.length}}
      There are {{blogPosts.length}} blog posts.
    {{/if}}
  {{/let}}
</template>
<template>
  {{#let user.posts as |blogPosts|}}
    {{#if blogPosts.length}}
      There are {{blogPosts.length}} blog posts.
    {{else}}
      There are no blog posts.
    {{/if}}
  {{/let}}
</template>

References