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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T07:30:10+00:00 2026-06-08T07:30:10+00:00

i need to template with handlebars an array of json object:(by chrome console) [object,object,object,object]

  • 0

i need to template with handlebars an array of json object:(by chrome console) [object,object,object,object] where every object is composed by this property:name,surname,ecc.

I’ve understood that is impossible to put array of object in handlebars but we must create an unique object with all property of all object of array.
Can anyone suggest me a function to create it

  • 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-08T07:30:11+00:00Added an answer on June 8, 2026 at 7:30 am

    You could set your array as a property of a wrapper object when calling the template.

    For example, with objects as the holding property

    var an_array = [
        {name: "My name"},
        {name: "Another name"}
    ];
    
    var source   = /* a template source*/;
    var template = Handlebars.compile(source);
    var wrapper  = {objects: an_array};
    
    console.log(template(wrapper));
    

    and your template can use this property as follows:

    <ul>
        {{#each objects}}
            <li>{{name}}</li>
        {{/each}}
    </ul>
    

    And a demo http://jsfiddle.net/YuvNY/1/

    var an_array=[
        {name:"My name"},
        {name:"Another name"},    
    ];
    
    var source   = $("#src").html();
    var template = Handlebars.compile(source);
    $("body").append( template({objects:an_array}) );
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
    <script src="http://builds.handlebarsjs.com.s3.amazonaws.com/handlebars-v2.0.0.js"></script>
    
    <script type='text/template' id='src'>
    <ul>
      {{#each objects}}
          <li>{{name}}</li>
      {{/each}}
    </ul>    
    </script>

    Or you could pass directly the array to the template and call the each helper with the context set to . (a dot)

    var template = Handlebars.compile(source);
    console.log(template(an_array));
    
    <ul>
        {{#each .}}
            <li>{{name}}</li>
        {{/each}}
    </ul>
    

    http://jsfiddle.net/nikoshr/YuvNY/32/

    var an_array=[
        {name:"My name"},
        {name:"Another name"},    
    ];
    
    var source   = $("#src").html();
    var template = Handlebars.compile(source);
    $("body").append( template(an_array) );
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
    <script src="http://builds.handlebarsjs.com.s3.amazonaws.com/handlebars-v2.0.0.js"></script>
    
    <script type='text/template' id='src'>
    <ul>
      {{#each .}}
          <li>{{name}}</li>
      {{/each}}
    </ul>    
    </script>
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to change template of confirmation email in FOSUserBundle. I have this settings,
I need to template some email texts. Nothing fancy, just replace something like @name@
I need a template like this, which work perfectly template <typename container> void mySuperTempalte
I'm looking for some background on this template (need a citation for a report).
I need to pass a dict and an object to a template. So, I
I've defined a DataTemplate in a ResourceDictionary. The template need some data (for populating
I need very basic template engine, which is incapsulated in single class. So I
I'm writing an XSLT template that need to output a valid xml file for
In my Django template I need to return the index of an item in
I need to create a Word template where I can choose from different paragraphs

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.