-
-
Notifications
You must be signed in to change notification settings - Fork 4.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
{{#each ...}}...{{else}}...{{/each}} #90
Comments
An I don't see anything wrong with this: {{#each todos as todo}}
<Todo description='{{todo.description}}' done='{{todo.done}}'/>
{{/each}}
{{#if todos.length === 0}}
<p>Nothing left to do! Congratulations, turn off your laptop and go outside</p>
{{/if}} Or this: {{#if todos.length}}
{{#each todos as todo}}
<Todo description='{{todo.description}}' done='{{todo.done}}'/>
{{/each}}
{{else}}
<p>Nothing left to do! Congratulations, turn off your laptop and go outside</p>
{{/if}} After all, this is the JavaScript way of doing it. |
There is a lot of precedent in other template languages for having an else branch for iteration. |
Sounds very convenient and the use-case is quite common, 1+ for |
In django, that cased is triggered in the empty clause of a for loop. |
Why not this?
Laravel uses that syntax, https://laravel.com/docs/5.3/blade#loops. |
Each/else is a built in helper for Handlebars. http://handlebarsjs.com/builtin_helpers.html |
needs documentation update in the example? |
Suggestion via Twitter – an
else
block for the special case when your array is empty:The text was updated successfully, but these errors were encountered: