Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8111925
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T02:18:01+00:00 2026-06-06T02:18:01+00:00

I am using underscore with backbone in a jsp app. In order to do

  • 0

I am using underscore with backbone in a jsp app.

In order to do that, I have used:

_.templateSettings = {
        interpolate : /\{\{(.+?)\}\}/g
    };

in order to have mustache-like templates so as to avoid jsp conflict.

Until this point everything is ok (i.e. filled correctly templates with simple values).

Now, I am trying to add a for loop inside the template in order to show a json array.

So I added this code:

<script type="text/template" id="im-template">
<div class="row">                                       
    <div class="horizontal-scroll">
        {{ for (var i = 0; i < data.length; i++) { 
            var template = data[i];
            alert(template.name);
        } }}
    </div>
</div>
</script>

But when running the app, I get:

Uncaught SyntaxError: Unexpected token for 

Do you know what could be the problem or how could I solve it?

Thanks in advance!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T02:18:02+00:00Added an answer on June 6, 2026 at 2:18 am

    You’re replacing the wrong regex, you want to replace the evaluate regex not the interpolate regex. From the fine manual:

    Define an interpolate regex to match expressions that should be interpolated verbatim, an escape regex to match expressions that should be inserted after being HTML escaped, and an evaluate regex to match expressions that should be evaluated without insertion into the resulting string.

    Interpolation is used to replace a template token with the result of a JavaScript expression but a for loop is not an expression in JavaScript.

    You want to replace the evaluate regex if you want to use a for loop like that:

    _.templateSettings.evaluate = /\{\{(.+?)\}\}/g;
    

    Demo: http://jsfiddle.net/ambiguous/gaYRb/

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using backbone's underscore templating engine with the mustache formatting patterns. I have already
I am using underscore.js's templating capabilities from backbone.js, I have the following template that
I'm using Backbone with Underscore templates. I have a JavaScript if() condition in my
I'm using Backbone and therefore Underscore to render my templates. My templates get rendered
I have a web application that is currently using backbone.js 0.5.3 with backbone local
I am using underscore template engine (as part of Backbone.js) and have an issue
When using backbone.js and the companion templating engine in underscore, I've noticed that most
I'm using backbone.js and underscore.js templates in a JSF application with Facelets. The issue
Using the standard English letters and underscore only, how many characters can be used
I am using backbone.js and underscore.js to build an javascript application. Since hours of

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.