Displaying user parameters in a meteor template

梦想与她 提交于 2019-12-10 12:54:27

问题


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.


回答1:


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

{{currentUser.profile.name}}




回答2:


Sorry, found my problem. I'm creating these test users in the startup code of my app. It seems the fields I thought I was populating I'm not.



来源:https://stackoverflow.com/questions/20311646/displaying-user-parameters-in-a-meteor-template

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!