Search code examples
meteorregisterhelper

Meteor using Template.registerHelpers,


I am trying to combine 2 beginner classes together (https://www.meteor.com/tutorials/blaze/templates & http://meteortips.com/second-meteor-tutorial/iron-router-part-1/). I have been able to complete both classes individually with no problem.

I am using Iron:Router to route to various templates. I run in to issues when I try to access a template within a template. The proper results do not get displayed on the " aostasks"page.

.js:

Router.route('aostask', {

    template: 'aostask'
});

 Tasks = new Mongo.Collection("tasks");

if (Meteor.isClient) {
  // This code only runs on the client
  Template.registerHelpers('task', function () {
      return tasks.find({});
    })
  };

.html:

<template name= "aostask">

    <head>
  <title>Todo List</title>
</head>

<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>

Result:

A page with the correct headers.However, it does not list the tasks i have in my mongo collection. Is the issue that i am using the registerHelper function incorrectly? Should i be using some other function?

Thanks in advance.


Solution

  • There is typo in your helper name

    Template.registerHelper('tasks', function () {
          return tasks.find({});
        })
      };
    

    tasks not task