Display an array of objects in HTML page


#1

My code :

Template.home.helpers({
contents() {
var contentArray = [];
var content1 =
{
‘contentName’: ‘test1’,
‘contentSize’: ‘test1’,
‘contentType’: ‘test1’,
};
var content2 =
{
‘contentName’: ‘test2’,
‘contentSize’: ‘test2’,
‘contentType’: ‘test2’,
};
contentArray.push(content1);
contentArray.push(content2);
return contentArray;
}
});

How can I display my “contents” in HTML page ?

{{#each contents}}

{{this.contentName}}
{{this.contentSize}}
{{this.contentType}}
{{/each}}

This doesn’t work for me :frowning:


#2

Try this:

{{#each contents}}
  {{contentName}} 
  {{contentSize}}
  {{contentType}}
{{/each}}

#3

I try it ! Doesn’t work …


#4

@jhuenges is correct. But so are you :wink:. Either of those forms will work, as will this:

<template name="home">
  {{#each content in contents}}
    {{content.contentName}}
    {{content.contentSize}}
    {{content.contentType}}
  {{/each}}
</template>

So, I wonder if you have got a template “home” and if you have invoked it ({{> home}})?


#5

It is working now ! I thought the problem is from this code or I missed something :frowning: But it’s okay now :wink: thank you