eco icon indicating copy to clipboard operation
eco copied to clipboard

Iterate over arrays

Open maccman opened this issue 14 years ago • 3 comments
trafficstars

Not sure if you want this in core, but it lets you pass an array to eco(), instead of an object, rendering the template over each item in the array. This is the standard in other templating libs, like jQuery.tmpl.

maccman avatar Sep 13 '11 17:09 maccman

It seems nice, but I kind of like restricting the template context to an object. Not a strong opinion though.

josh avatar Sep 13 '11 17:09 josh

@sstephenson worth me refactoring the array check? Is this something you'd like to see in core?

@josh - the template context will still be an object, the array index.

maccman avatar Sep 21 '11 15:09 maccman

+1. I ended up writing myself a helper function to template an array at first (this is what i was used to from other libraries). Since then i've been been doing <% for item, i in @: %> because it gives me access to the iterator in the template (which is desired IMO). Would for sure want access to the iterator if the library decided to take this one on. I suppose this is more of a connivence and an necessity. Is the recommended behavior to do as i have been with <% for item, i in @: %>?

ckihneman avatar Apr 20 '12 18:04 ckihneman