#87 each else

I am always surprised by how many people are not aware of this and it is probably because it is rare to have an “else” construct for a loop. Most programming languages don’t have that. But handlebars templating does and it is very handy.

Did you know you could do?

{{#each posts as |post|}}
<div> {{post.title}}</div>
{{else}}
<div>There are no posts to show.</div>
{{/each}}

The {{else}} part is displayed when the list you are looping over is empty.


Originally published at Ember Daily Tips.