I'm struggling to pass data from one template to another, and thinking about it I wonder if that's my problem anyway. I'm using the built in accounts system, I have adding new users and authentication working, and when a user signs in I forward them to a new template. I'd like to be able to use their details in that template but I'm struggling to figure out the best way to do this.
Initially I thought I could simply use: Router.go('userPage', {user:username});
which gives no errors but doesn't work. In my template I'm using : <p>Welcome {{user}}</p>
Using {{> user}}
throws an 'Can't find template, helper or data context key: username'
error.
Any ideas?
EDIT: Ignore the rest, after restarting the Meteor server this is now working.
Thinking I have a bigger issue here so adding more detail:
Taking some info from a form and then routing based upon the outcome:
Meteor.loginWithPassword(username, password, function(err) {
if (err) {
console.log('Logging in failed');
} else {
console.log('Logging in succeeded');
console.log(username);
Router.go('userPage');
}
});
I then wish to open this template and pass through the data of the user who just logged in:
<template name="userPage">
<div class="container">
<h1>Welcome {{username}}</h1>
</div>
<p>User Page</p>
</template>
If I use <p>Welcome {{currentUser.username}}</p>
I get no errors but also no name. Meteor.user().username
does return a name but I cannot get that into the template.
Welcome {{currentUser.username}}
` gives me no errors but also doesn't pass any data. If I log `Meteor.user().username` I get a string fine. I think I have a bigger problem going on :) I'll add more detail to my question. – Tortex May 24 '14 at 20:09