bminer / node-blade

Blade - HTML Template Compiler, inspired by Jade & Haml
Other
320 stars 28 forks source link

foreach with index #179

Closed bioform closed 10 years ago

bioform commented 11 years ago

at current point it is impossible to use index field with foreach by cursor(meteorjs) since foreach block is invoked with async way. Each time the following code show different results:

- var i=0
foreach posts as post
    include 'item' exposing i, post
    - i++
bminer commented 11 years ago

Thanks for the bug report.

Unfortunately, I am out of the country travelling at the moment, and it will be some time before I can fix some of the bugs for Blade.

Would you be willing to investigate further or propose some sort of solution? Thanks again.

bioform commented 11 years ago

The same issue exists in meteor handlebars: https://github.com/meteor/meteor/pull/912

I mean iteration with mongo cursor

bminer commented 11 years ago

This can be implemented by listening for addedAt events instead of added events. See http://docs.meteor.com/#observe

Adding the index for Array objects is trivial.

I don't have time to add this at the moment, but it seems like an easy change. Pull requests are graciously accepted.

bminer commented 10 years ago

Closing this issue. The foreach syntax is now deprecated.

I understand that people want the functionality of a "foreach" statement, so there will probably be a foreach replacement coming soon.