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 6824153
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T21:52:05+00:00 2026-05-26T21:52:05+00:00

I am using backbone.js and underscore.js to build an javascript application. Since hours of

  • 0

I am using backbone.js and underscore.js to build an javascript application. Since hours of reading and trying to run a template within a template like below, it is getting more and more frustrating.

My template using the build in underscore.js template engine:

<script id="navigation_template" type="text/template">
  <div><%= title %>
      <% _.each(children, function(child) { %>
          <% render_this_template_recursively(child) %>
      <% }); %>
  </div>
</script>

I would like to render this template for every child element ( render_this_template_recursively(child) ).

How can I do this?

Thanks

  • 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-05-26T21:52:05+00:00Added an answer on May 26, 2026 at 9:52 pm

    I’ve not personally tried this but _.template returns a function (I’ve named it templateFn to emphasize that), so you could pass it into the template like this:

    var templateFn = _.template($('#navigation_template').html());
    
    $(this.el).html(templateFn({model: this.model, templateFn: templateFn}));
    

    Notice that i’m passing in the whole model (assuming that your model has a children property which is itself a collection of backbone models) and your template would be changed to:

    <script id="navigation_template" type="text/template">
      <div><%= model.escape('title') %>
          <% _.each(model.children, function(child) { %>
              <%= templateFn(child, templateFn) %>
          <% }); %>
      </div>
    </script>
    

    Good luck. I hope this works for you

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

Sidebar

Related Questions

I am using underscore.js's templating capabilities from backbone.js, I have the following template that
Using Backbone I can fetch the Collection like below and render a Backbone View
Using the below XML, I need to figure out which person worked more hours
I've developed a nice rich application interface using Backbone.js where users can add objects
I've just started using Backbone (and Underscore) JS. We are doing a big iPad
I am building a js heavy app using backbone.js. One problem I've run into
I made a registration form using backbone.js, CoffeeScript and jquery. I am trying to
I'm trying to test some backbone.js views using Jasmine (via jasmine-headless-webkit). Everything is working
Currently I am using backbone-rails in my Rails app. I would like to know
I'm using Backbone.js's routing . It generate urls for browsers like this: http://my-app.com/help For

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.