Permalink
Browse files

Display comments on `postPage`.

chapter10-2
  • Loading branch information...
tmeasday committed Apr 8, 2013
1 parent db88c3f commit 62f7eb017b520bb1b8e35fc8ca568b56463d674f
@@ -0,0 +1,9 @@
+<template name="commentItem">
+ <li>
+ <h4>
+ <span class="author">{{author}}</span>
+ <span class="date">on {{submittedText}}</span>
+ </h4>
+ <p>{{body}}</p>
+ </li>
+</template>
@@ -0,0 +1,5 @@
+Template.commentItem.helpers({
+ submittedText: function() {
+ return this.submitted.toString();
+ }
+});
@@ -3,7 +3,8 @@
<div class="post-content">
<h3><a href="{{url}}">{{title}}</a><span>{{domain}}</span></h3>
<p>
- submitted by {{author}}
+ submitted by {{author}},
+ <a href="{{pathFor 'postPage'}}">{{commentsCount}} comments</a>
{{#if ownPost}}<a href="{{pathFor 'postEdit'}}">Edit</a>{{/if}}
</p>
</div>
@@ -6,5 +6,8 @@ Template.postItem.helpers({
var a = document.createElement('a');
a.href = this.url;
return a.hostname;
+ },
+ commentsCount: function() {
+ return Comments.find({postId: this._id}).count();
}
});
@@ -1,5 +1,11 @@
<template name="postPage">
<div class="post-page page">
{{> postItem}}
+
+ <ul class="comments">
+ {{#each comments}}
+ {{> commentItem}}
+ {{/each}}
+ </ul>
</div>
</template>
@@ -0,0 +1,5 @@
+Template.postPage.helpers({
+ comments: function() {
+ return Comments.find({postId: this._id});
+ }
+});

2 comments on commit 62f7eb0

@HmadAmani

This comment has been minimized.

Show comment
Hide comment

lksv

@HmadAmani

This comment has been minimized.

Show comment
Hide comment

vs

Please sign in to comment.