简体   繁体   English

流星个人资料页面检查当前用户是否是页面所有者

[英]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 我已经为所有用户设置了一个带有个人资料页面的Meteor项目,并提供了以下问题的答案: SO问题

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. 关于路由数据来自何处以及可以在何处使用等问题有些困惑。

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}}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM