Barry Michael Doyle
Barry Michael Doyle

Reputation: 10608

Meteor profile page check if current user is page owner

I've set up a Meteor project with profile pages for all my users with guidance from the answer of this question: SO Question

I wanted to know how I could display edit buttons to the user if they are the owner of the profile page.

Eg here's my template:

<template name="profile">
{{#if <!-- Insert condition here -->}}
  <!-- page owner content only -->
{{/if}}
<!-- Content for all to see -->
</template>

What condition would I need to place in the handlebar to display the page owner content only? Are the template helpers or can I make my own condition?

Just a bit confused as to where the data from the route comes from and where it can be used etc.

Upvotes: 0

Views: 128

Answers (1)

Ricardo Pesciotta
Ricardo Pesciotta

Reputation: 393

You can create a helper that analyzes if the user logged in it the same as the path you used to access the page. Something like this:

Template.profile.helpers({
    'isMyProfile': function() {
        return Router.current().params.username == Meteor.user.username
    }
});

Then on the template, you could call:

{{#if isMyProfile}}
    <button>...</button>
{{/if}}

Upvotes: 2

Related Questions