baryshev / ect

Fastest JavaScript template engine with embedded CoffeeScript syntax

Home Page:http://ectjs.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

No output from loop when used on object

cjmarkham opened this issue · comments

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

Try <% for forum of @forums %>

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.