0

I'm trying to add this if statement in a loop in an underscore template:

<% _.each( looks, function( listItem, index ){ %>   
             <% if(_.contains(firstBatch, listItem.id)){ %> 
                <% if (index % 2 == 0) { %>
                        <div class="large-6 column overlay-col">  
                <% }  else { %>
                        <div class=" column overlay-col">
                <% } % %>
            <% } %>                                                                  
<% }) %>

Basically it's to detect if index is an even number, but I get this console error:

SyntaxError: missing : after property id
if (index % 2 === 0) {

what's wrong with code?

1 Answer 1

1

I think your syntax has a bozo on line 7:

 <% } % %>

What's that extra percent?

This becomes apparent when you remove all the decoration around the function:

_.each( looks, function( listItem, index ){    
  if(_.contains(firstBatch, listItem.id)){  
    if (index % 2 == 0) { 
      <div class="large-6 column overlay-col">  
    }  else { 
      <div class=" column overlay-col">
    } % 
  }                                                                   
}) 
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.