Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Displaying user parameters in a meteor template

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.

like image 836
Peter Nunn Avatar asked Dec 01 '13 11:12

Peter Nunn


2 Answers

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

{{currentUser.profile.name}}

like image 142
Peppe L-G Avatar answered Nov 08 '22 04:11

Peppe L-G


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.

like image 22
Peter Nunn Avatar answered Nov 08 '22 04:11

Peter Nunn