Templates.helpers.if()

ifpublic

Defined in packages/ember-htmlbars/lib/helpers/if_unless.js:9

Use the if block helper to conditionally render a block depending on a property. If the property is "falsey", for example: false, undefined, null, "", 0, NaN or an empty array, the block will not be rendered.

{{! will not render if foo is falsey}}
{{#if foo}}
  Welcome to the {{foo.bar}}
{{/if}}

You can also specify a template to show if the property is falsey by using the else helper.

{{! is it raining outside?}}
{{#if isRaining}}
  Yes, grab an umbrella!
{{else}}
  No, it's lovely outside!
{{/if}}

You are also able to combine else and if helpers to create more complex conditional logic.

{{#if isMorning}}
  Good morning
{{else if isAfternoon}}
  Good afternoon
{{else}}
  Good night
{{/if}}

You can use if inline to conditionally render a single property or string. This helper acts like a ternary operator. If the first property is truthy, the second argument will be displayed, if not, the third argument will be displayed

{{if useLongGreeting "Hello" "Hi"}} Dave

Finally, you can use the if helper inside another helper as a subexpression.

{{some-component height=(if isBig "100" "10")}}
doc_EmberJs
2016-11-30 16:53:34
Comments
Leave a Comment

Please login to continue.