baryshev / ect

Fastest JavaScript template engine with embedded CoffeeScript syntax
http://ectjs.com
MIT License
627 stars 70 forks source link

No output from loop when used on object #65

Closed cjmarkham closed 10 years ago

cjmarkham commented 10 years ago

I am using ECT with SailsJS. I have called res.view() within a controller and included the parameters for the template:

res.view({ title: 'home', forums: forums });

forums is an object with several children. A console.log() of this object on the server shows all of the properties.

However, when I use this object in the ECT template I get nothing

<% for forum in @forums %>

I decided to output the contents of @forums and encode it using JSON.

<%= @helpers.jsonEncode @forums %>

(jsonEncode helper is just using JSON.stringify).

This does indeed output the whole object. So why is nothing rendered in my for loop

yuri-karadzhov commented 10 years ago

Try <% for forum of @forums %>

baryshev commented 10 years ago

You are trying to walk through object as an array. @yuri-karadzhov suggested solution will solve your problem. You can use http://js2coffee.org/ to check your CoffeeScript syntax.