You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I suggest the following feature for foreach: alognside with else block which is rendered when collection is empty, there may be:
header block, which is executed before iterating over collection
trailer block, which is executed after iterating over collection
enclose block, rendering around
All of those are run only if the collection is not empty:
foreach users as user
tr
td #{user.firstName}#{user.lastName} (#{user.age})
header
tr
th User name and age
trailer
tr
td You have #{users.length} users today
enclose
table
else
p No users were found
I don't know how hard to implement and/or useful this would be, but almost every collection has a custom rendering depending on whether it's empty or not.
The text was updated successfully, but these errors were encountered:
Interesting feature... I will have to think about this... my initial reaction is that it's almost more confusing syntax than simply adding a - if(users.length > 0) .... else .... block.
I like your idea... just not the syntax proposed, especially the enclose keyword. My opinion only... I think the extra indenting improves readability even though it is, perhaps, more verbose.
I think I will close this issue for now, but if you have any other ideas, I'd certainly welcome them.
I suggest the following feature for
foreach
: alognside withelse
block which is rendered when collection is empty, there may be:header
block, which is executed before iterating over collectiontrailer
block, which is executed after iterating over collectionenclose
block, rendering aroundAll of those are run only if the collection is not empty:
I don't know how hard to implement and/or useful this would be, but almost every collection has a custom rendering depending on whether it's empty or not.
The text was updated successfully, but these errors were encountered: