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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T06:39:02+00:00 2026-06-16T06:39:02+00:00

Underscore templates seem pretty simple, but I’m working on my first attempt and am

  • 0

Underscore templates seem pretty simple, but I’m working on my first attempt and am stumped.

I’m just trying to display a person’s name in the H1.

Here’s my template:

<script id="tmpl-index-list" type="text/template">
<% _.each(data, function(item){  %>
    <li>
        <a href="#person" data-transition="slide">
            <h1><%=item.personName%></h1>
        </a>    
    </li>
<% }); %>                  

And here’s my JS:

var tmplMarkup = $('#tmpl-index-list').html();
var compiledTmpl = _.template( tmplMarkup, {data: IndexList.listEntries} );
$('#index-list-wrapper').html(compiledTmpl);

IndexList.listEntires is an array of ListEntry objects, simple key / value objects.

For example, here is the ‘class’:

function ListEntry(){
    this.img_url = '';
    this.personName = '';
    this.personID = '';
};

When I do a console.dir on it, the data is there, but for item.personName in the template, it comes up as undefined.

What am I missing?

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-16T06:39:03+00:00Added an answer on June 16, 2026 at 6:39 am

    I believe the problem is with the data you are passing in. You are using IndexList.listEntries, but you have not provided any example data.

    Based on your comments, that listEntries is an array of objects like ListEntry, I have put together some sample data.

    var IndexList = {
        listEntries : [
            {
                "img_url" : "http://www.gravatar.com/avatar/72b3fbc4d71d3955deca44483322da23?s=32&d=identicon&r=PG",
                "personName" : "Tim",
                "personId" : "Tim76"
            },
            {
                "img_url" : "http://www.gravatar.com/avatar/0927a92a180a7552e2119742ede9b9cf?s=128&d=identicon&r=PG",
                "personName" : "Rob",
                "personId" : "Robert Price"
            }
        ]
    };
    

    Using this data, your template correctly shows both “Tim” and “Rob” as list items when run.

    I suggest you go and look again at the IndexList data you are trying to use, the problem is almost certainly there.

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

Sidebar

Related Questions

Just getting started here and cannot seem to get this very basic thing working.
This is my configure file: The layout.jade does not seem to be working. But
I'm trying to use backbone.js with underscore.js templates in an asp.net web forms application
I'm having a very funky problem with Underscore.js templates. In all browsers but IE
I'm trying to render an html table using underscore template engine. First I have
im trying to use templates for my backbone views. I tried it with underscore.template
I am using the following code to load two underscore.js templates. Once the first
I have JavaScript application, where I use client-side templates (underscore.js, Backbone.js). Data for initial
I've built a system that uses underscore-js to render templates, and it works fine
I'm using Backbone and therefore Underscore to render my templates. My templates get rendered

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.