在流星模板中显示用户参数 [英] Displaying user parameters in a meteor template

查看:90
本文介绍了在流星模板中显示用户参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我正试图简单地显示用户名和一些当前登录的用户的配置文件参数,我没有太多。



到目前为止我所做的搜索似乎表明我需要使用帮助器函数来访问像

  Meteor.user().profile.name 

将其设置为一个变量,然后可以在句柄中使用它。这是正确的吗?



不可能简单地

{{Meteor。用户()。profile.name}} 在模板中并显示它?



这当然不适合我。 p>

编辑显示代码....
对不起,应该把它放在前面。



我使用的代码如下。 currentUser(因为我现在使用谢谢下面的答案)显然定义为loggedInPageLayout正在显示,但我无法从currentUser获取任何信息,无论是在此页面上还是在loggedInPageLayout页面上。

  template name =loginPage> 
< div>
{{#if currentUser}}
< div>
您已登录{{currentUser.username}}
{{> loggedInPageLayout}}
< / div>
{{else}}
{{> loginPageLayout}}
{{/ if}}
< / div>
< / template>

彼得

解决方案

您可以使用 currentUser 助手,该助手返回 Meteor .user()



{{currentUser.profile.name}}


I'm trying to work out how to do something really simple but it has me stumped.

I'm trying to simply display the user name and some of the profile parameters of the currently logged in user and I'm not getting far.

The searching I've done so far seems to indicate that I need to use a helper function to access things like

Meteor.user().profile.name

setting it to a variable that I can then use in handlebars. Is this correct?

Is it not possible to simply

{{Meteor.user().profile.name}} in the template and have it display?

This certainly isn't working for me.

Edit to show code.... Sorry, should have put this in earlier.

The code I'm using is as follows. currentUser (as I'm now using thanks to answer below) is obviously defined as the loggedInPageLayout is displaying, but I can't get any information out of currentUser either on this page or on the loggedInPageLayout page.

template name="loginPage">
<div>
  {{#if currentUser}}
    <div>
      You are logged in {{currentUser.username}}
      {{> loggedInPageLayout}}
    </div>
  {{else}}
    {{> loginPageLayout}}
  {{/if}}
</div>
</template>

Peter.

解决方案

You can use the currentUser helper, which returns Meteor.user():

{{currentUser.profile.name}}

这篇关于在流星模板中显示用户参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆