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

时间:2016-03-29 19:54:58

标签: javascript meteor iron-router user-profile

我已根据此问题的答案为我的所有用户设置了包含个人资料页面的Meteor项目:SO Question

我想知道如果他们是个人资料页面的所有者,我可以向用户显示编辑按钮。

例如,这是我的模板:

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

我需要在车把中放置什么条件才能显示页面所有者的内容?是模板帮助者还是我可以自己创造条件?

对于来自路线的数据来源以及可以使用的地方等等,我们感到有点困惑。

1 个答案:

答案 0 :(得分:2)

您可以创建一个帮助程序,分析用户登录时是否与您用于访问该页面的路径相同。像这样:

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

然后在模板上,您可以致电:

{{#if isMyProfile}}
    <button>...</button>
{{/if}}
相关问题