Old Guides - You are viewing the guides for
Ember
v1.10.0.
Sometimes you may only want to display part of your template if a property exists.
We can use the {{#if}}
helper to conditionally render a block:
<b> </b>!
Welcome back,
Handlebars will not render the block if the argument passed evaluates to
false
, undefined
, null
or []
(i.e., any "falsy" value).
If the expression evaluates to falsy, we can also display an alternate template
using {{else}}
:
<b> </b>!
Please log in.
Welcome back,
To only render a block if a value is falsy, use {{#unless}}
:
You owe: $
{{#if}}
and {{#unless}}
are examples of block expressions. These allow you
to invoke a helper with a portion of your template. Block expressions look like
normal expressions except that they contain a hash (#) before the helper name,
and require a closing expression.