Reputation: 5
I'm currently learning the meteor framework, and right now I can't quite understand why my code isn't working. I'm attempting to create a template called "time" that has a variable called "date" which uses new Date(); to display the date and time on my HTML file, but it isn't working. All it shows is "the time now is" without showing the time.
Here's my HTML and JS file (I tried to make it following the same logic for the first template images which my course uses):
HTML:
<head>
<title>my_first_app</title>
</head>
<body>
<h1>Hello from Greece!</h1>
{{>time}}
</body>
<template name="time">
<p>The time now is {{date}}</p>
</template>
Javascript:
import { Template } from 'meteor/templating';
import { ReactiveVar } from 'meteor/reactive-var';
import './main.html';
var date = new Date();
Template.time.helpers({
time: function(){
return new Date();
}
});
Upvotes: 0
Views: 167
Reputation: 683
You just need to change your helper name in the template to 'time' instead of 'date' or to reduce ambiguity you can do like this:
<head>
<title>my_first_app</title>
</head>
<body>
<h1>Hello from Greece!</h1>
{{>time}}
</body>
<template name="time">
<p>The time now is {{timeVal}}</p>
import { Template } from 'meteor/templating';
import { ReactiveVar } from 'meteor/reactive-var';
import './main.html';
var date = new Date();
Template.time.helpers({
timeVal: function(){ return new Date(); }});
Upvotes: 3