Meteor came out of beta, and I am very excited to use it. I installed it on my windows machine (from /) and created an app. Here's the code:
html:
<!-- simple-todos.html -->
<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 name="task">
<li>{{text}}</li>
</template>
javascript:
// simple-todos.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" }
]
});
}
It is the exact same code as in the official meteor tutorial. If I run the example, the title is rendered just fine. The list on the other hand doesn't appear at all. Somehow, the helpers do not work. I get the following javascript error:
Uncaught TypeError: Cannot read property 'helpers' of undefined
In the meteor console, no error or warning was printed. I am very excited about meteor and I would love to use it in the future for production apps, so please help me with this (probably very simple) problem. I hope it is not only a problem in windows (meteor hasn't yet been officially released for windows).
Meteor came out of beta, and I am very excited to use it. I installed it on my windows machine (from http://win.meteor./) and created an app. Here's the code:
html:
<!-- simple-todos.html -->
<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 name="task">
<li>{{text}}</li>
</template>
javascript:
// simple-todos.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" }
]
});
}
It is the exact same code as in the official meteor tutorial. If I run the example, the title is rendered just fine. The list on the other hand doesn't appear at all. Somehow, the helpers do not work. I get the following javascript error:
Uncaught TypeError: Cannot read property 'helpers' of undefined
In the meteor console, no error or warning was printed. I am very excited about meteor and I would love to use it in the future for production apps, so please help me with this (probably very simple) problem. I hope it is not only a problem in windows (meteor hasn't yet been officially released for windows).
Share Improve this question asked Nov 8, 2014 at 16:08 LucaLuca 5581 gold badge4 silver badges18 bronze badges 1-
First thing I'd do is add
console.dir(Template);
before the attempted call to.helpers()
. The issue is that.body
isundefined
, so it'd be useful to figure out whatTemplate
actually looks like. – Pointy Commented Nov 8, 2014 at 16:11
1 Answer
Reset to default 5Template needs to be defined by <template name="xxx">
.
There is no helper on the <body>
element.
You could use a global helper for this, though:
Template.registerHelper("tasks", function() {
return [....]
});
An alternative is to use <template name="body">
:
<body>
{{>body}}
</body>
<template name="body">
<div class="container">
<header>
<h1>Todo List</h1>
</header>
<ul>
{{#each tasks}}
{{> task}}
{{/each}}
</ul>
</div>
</template>