{{if}}

Conditionally renders a block or returns one of two inline values.

Since Ember 4/5 (Octane) Spec ↗

Syntax

{{#if cond}}...{{else}}...{{/if}} | {{if cond a b}}

Returns

block | value — The truthy branch or its inline value.

Examples

{{#if this.isLoading}}
  <Spinner />
{{else if this.error}}
  <Error @message={{this.error}} />
{{else}}
  <Results @data={{this.data}} />
{{/if}}
<button type="button" disabled={{if this.busy "disabled"}}>
  {{if this.busy "Saving..." "Save"}}
</button>

Notes

Block form supports {{else if}} chains. Inline form {{if cond a b}} returns a or b and is handy for attributes. Ember truthiness treats empty arrays and empty strings as falsy.