[英]Meteor profile page check if current user is page owner
我已经为所有用户设置了一个带有个人资料页面的Meteor项目,并提供了以下问题的答案: SO问题
我想知道如果编辑按钮是个人资料页面的所有者,如何向用户显示编辑按钮。
例如,这是我的模板:
<template name="profile">
{{#if <!-- Insert condition here -->}}
<!-- page owner content only -->
{{/if}}
<!-- Content for all to see -->
</template>
我需要在车把中放置什么条件才能仅显示页面所有者的内容? 是模板助手,还是我可以自己确定条件?
关于路由数据来自何处以及可以在何处使用等问题有些困惑。
您可以创建一个助手来分析用户登录时是否与您访问该页面所使用的路径相同。 像这样:
Template.profile.helpers({
'isMyProfile': function() {
return Router.current().params.username == Meteor.user.username
}
});
然后在模板上,您可以调用:
{{#if isMyProfile}}
<button>...</button>
{{/if}}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.