gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-02 14:49:32 25 4
gpt4 key购买 nike

在这个问题的答案的指导下,我已经为所有用户设置了一个带有个人资料页面的 Meteor 项目:SO Question

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

例如,这是我的模板:

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

我需要在 Handlebars 中放置什么条件才能仅显示页面所有者内容?模板是助手还是我可以制定自己的条件?

只是对路由中的数据来自哪里以及可以在哪里使用等感到有点困惑。

最佳答案

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

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

然后在模板上,您可以调用:

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

关于javascript - Meteor 个人资料页面检查当前用户是否是页面所有者,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36293928/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com