-
Notifications
You must be signed in to change notification settings - Fork 26
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Example blog with posts and comments #6
Comments
Not all collections must be entities, entities should only be the ones that are editable in the admin. Declare the collection Comments = new Mongo.Collection('comments');
Comments.attachSchema(new SimpleSchema({
content: {
type: String,
autoform: {
label: false,
placeholder: 'Message'
}
},
postId: {
type: String,
},
createdAt: {
type: Date,
autoValue: function() {
return new Date;
}
},
createdBy: {
type: String,
autoValue: function() {
return this.userId;
}
}
})); Create the publication Meteor.publish('commentsForPost', function (postId) {
return Comments.find({ postId: postId });
}); Use template level subscriptions to subscribe to the comments Template.post.onRendered(function() {
this.subscribe('commentsForPost', this.data._id)
}) Create the template helper to fetch the comments Template.post.helpers({
comments: function () {
return Comments.find({ postId: this._id }, { sort: { createdAt: -1 } });
}
}); Put them in the html code <template name="post">
...
{{# each comments }}
<p><b>{{ getUserName }}</b></p>
<p>{{ content }}</p>
<p>{{ timeago createdAt }}</p>
{{/ each }}
</template> Create the form and with it event Template.post.events({
'click .comment-btn': function () {
Comments.insert({ postId: this._id, content: $(".comment-content").val() });
}
}); If you have any questions you can ask |
The remind "Not all collections must be entities, entities should only be the ones that are editable in the admin." really helps a lot! |
Another question maybe not directly related to orion, that is how to define dynamic Schema (form)? For example, in my resource_create template, I want to do the following: Which means in MongoDB, I'd like to store resources with different schema (minor difference) in one collection. How could I do that if I assign SimpleSchema? |
Thats completely aldeed/meteor-simple-schema. Maybe you can make the dynamic values optional depending if a Boolean "isMovie" |
I found this https://github.com/orionjs/tutorials/blob/master/tutorials/custom_entity_templates.md useful to this case. |
Could you please give a detailed example blog having comments related to a post?
The
comments_list
andcomment_create
templates are at front-end in post page, and I can also see the comments I submitted at admin panel -> comments entity -> index page.Another problem is that for different entities, such as
posts
andresources
, I want to have a unified comments functionality related to them, how can I do that? And can you give an example for that? Thanks a lot!The text was updated successfully, but these errors were encountered: