swayziak
swayziak

Reputation: 353

Meteor template isn't rendering properly

I'm building a notifications page, where the user can see which posts have comments, and I want to display the date of each post, but it's not working.

Here is the code:

<template name="notification">
    <li><a href="{{notificationPostPath}}">Someone commented your post, {{postDate}}</a> </li>
 </template>


 Template.notification.helpers({
       notificationPostPath: function() {
            return Router.routes.PostPage.path({_id: this.postId});
       },
       post: function () {
    return Post.findOne({_id: this.postId});
       },
       postDate: function() { 
            return moment(post.submitted).format('dddd, MMMM Do');
      }
  });

The console prints this: Exception from Deps recompute: ReferenceError: post is not defined.

Thanks in advance

Upvotes: 0

Views: 33

Answers (1)

richsilv
richsilv

Reputation: 8013

I assume the error is being flagged on the following line:

return moment(post.submitted).format('dddd, MMMM Do');

Note that you can't refer to helpers from within other helpers like that (and anyway, post is a function) - you need too add another line at the start of the postDate helper like this:

var post = Post.findOne({_id: this.postId});

Upvotes: 1

Related Questions