用户配置文件/路由器

时间:2013-09-22 19:17:33

标签: meteor router

我正试图弄清楚如何通过前往/ player /:username来查看用户个人资料。我有模板,现在我只需要调用Meteor.users通过URL中指定的:username找到用户帐户。我正在使用路由器包。

'/player/:username': { 
    to: 'user_profile', 
    and: function(){ 
        var user = Meteor.users.findOne({ username: username }); 
    } 
},

提前致谢, 森

2 个答案:

答案 0 :(得分:3)

我会在路由功能中设置Session变量,然后使用它在模板助手中返回用户。所以:

'/player/:username': { 
    to: 'user_profile', 
    and: function(username){ 
        Session.set('currentUsername', username); 
    } 
},

然后在模板助手

Template.user_profile.helpers({
  currentUser: function() {
    return Meteor.users.findOne({username: Session.get('currentUsername')});
  }
})

然后在你的模板中

<template name="user_profile">
{{#with currentUser}}
User name is {{username}}
{{/with}}
</template>

答案 1 :(得分:1)

您可以尝试var user = Meteor.users.findOne({ username: username }); - 然后查找用户的个人资料属性,您可以user.profile.foobar

相关问题