kaha
kaha

Reputation: 1417

underscore.js template error

I'm trying to load .txt file to <div> and when .txt have code like this

<h1>Hello <%= name %></h1>

It is working properly, but when I have some code like this

<select name="action_edit" id="task_action_edit">
    <option value="none">None</option>
    <%
    foreach(actions as action) {
        if(action['id'] == 2) {
        %>
            <option selected="selected" value="<%= action['id'] %>" action_abbr="<%= action['title'] %>">
                <%= action['title'] %>
            </option>
        <%                                
        } else {
        %>
            <option value="<%= action['id'] %>" action_abbr="<%= action['title'] %>">
                <%= action['title'] %>
            </option>
        <%
        }
    }
    %>
</select>

Firefox showing me this error when I'm loading this .txt code to div

missing ) after argument list
[Break On This Error] var __p=[],print=function(){__p.push.a... </select>');}return __p.join('');
underscore.js (line 779)

What I'm doing wrong?

Thanks,

Upvotes: 0

Views: 1885

Answers (1)

mu is too short
mu is too short

Reputation: 434945

Underscore's templates use JavaScript inside the <% ... %> delimiters. This:

foreach(actions as action) {

is not JavaScript and that could lead to the odd error you're seeing. Maybe you mean:

for(action in actions) {

in your template.

Upvotes: 1

Related Questions