Template Helper Not Working

Hi, I am trying to finish an assignment but the template helper doesn’t seem to work. Any help will be much appreciated!!

Assignment is to display comments according to siteId…

I add a template helper to return comments if the siteid matches

Template.discussSite.helpers({
    'comments':function(siteId){
        return Comments.find({"siteId":siteId});
    }
});

but the comments are not saving. What am I doing wrong here?

On the HTML, I inserted

<template name="discussSite">
    <h3>Discussing: {{url}} </h3>
    {{> addCommentForm}}

    {{#each comments}}
    <h5>{{text}} by {{createdBy}} on {{createdOn}}</h5>
    {{/each}}

</template>

Thanks!

Is there code to insert the comment into the Comments collection? maybe in the click event handler for that add button or the submit event for the form. if not i’d add some :slight_smile:

Hi! Is this good?

Template.addCommentForm.events({
 'click .js-add-comment':function(event){
     var comment_text = $('#comment_input').val();// get the form value using jquery...
     var user = 'anonymous person';
     // the 'this' variable contains
     // the data that this template is displaying
     // which is the Website item
     var site = this;
     if (Meteor.user()){
         user = Meteor.user().emails[0].address
     }
     var comment = {"text":comment_text,
                    "siteId":site._id,
                 "createdOn":new Date(),
                 "createdBy":user};// create a simple object to insert to the collectoin
    Comments.insert(comment);
     return false;
 }
});

at first glance yea. I just didnt know if you had gotten that far in the project :slight_smile:

I would double check the contents of the collection in Minimongo by opening the browsers console and checking the Comments collection to see if it has items inside of it after running that event handler

thanks @brianmulhall! i figure it out :slight_smile:

Template.discussSite.helpers({
    'comments':function(siteId){
        return Comments.find({"siteId":**this._id**});
    }
});

all submitted :upside_down_face: Thanks for replying!

no problem, glad you figured it out :slight_smile: