0

I have the following three files:

  • abc.js
  • abc.html
  • router.js

The each statement in HTML does not output data if it the HTML is surrounded by template. Removing the template is outputting data.

//file name : abc.js

if (Meteor.isClient) {
  // This code only runs on the client
  Template.body.helpers({
    tasks: [
      { text: "This is task 1" },
      { text: "This is task 2" },
      { text: "This is task 3" }
    ]
  });
}
//file name router.js

Router.map(function () {
  this.route('mylist',{
    path:'/list',
  });
});
//file name: abc.html

<template name="mylist">
<body>
  <div class="container">
    <header>
      <h1>Todo List</h1>
    </header>

    <ul>
      {{#each tasks}}
        {{> task}}
      {{/each}}
    </ul>
  </div>
</body>
</template>

<template name="task">
  <li>{{text}}</li>
</template>

Why doesn't the template output data with the #each statement?

0

1 Answer 1

1

You are using Template.body.helpers instead of mylist helpers.
Try to modify your code as below:

if (Meteor.isClient) {
  // This code only runs on the client
  Template.mylist.helpers({
    tasks: [
      { text: "This is task 1" },
      { text: "This is task 2" },
      { text: "This is task 3" }
    ]
  });
}

You should also remove <body> tag from mylist template and include your template mylist on your html body:

<body>
{{>mylist}}
</body>

<template name="mylist">

  <div class="container">
    <header>
      <h1>Todo List</h1>
    </header>

    <ul>
      {{#each tasks}}
        {{> task}}
      {{/each}}
    </ul>
  </div>

</template>

<template name="task">
  <li>{{text}}</li>
</template>
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks GUISSOUMA.. Your answered Helped. :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.