How to hide links for delete and edit


#1

Hello. How do I hide the edit and delete buttons for my posts so that the user who created the post is the only one who can see the buttons.

I’m guessing the restriction would look like this within the template…

                      {{#if ownsPost}}
                              <button>delete</button>
                       {{/if}}

So that only the owner can see it. But how do I configure the code for “ownsPost”? How do I implement this feature.


#2

You’re looking for template helpers. http://docs.meteor.com/api/templates.html#Template-helpers

For this kind of functionality I would suggest looking into the demo app:
https://www.meteor.com/tutorials/blaze/


#3

Try find a tutorial that covers it. Should look something like this. This the helper for whatever template is handling the data.

Template.postPage.helpers({
ownPost: function() {
return this.userId == Meteor.userId();
}
});


#4
{{#if ownsPost}} delete {{/if}}

Template.getUserStatus.helper({
isOwner: function() {
return true;//you can take any code here like mongo lookup
}
});


#5

@sandeepmeenuga I just solved it. The code to use is…

      Template.message.helpers({
         isOwner: function() {
         return this.userId === Meteor.userId();
         }
      });

But one you HAVE to set userId to Meteor.userId() with your event helper. Please mention this the next time. Thanks so much.