What I don’t understand is where I put this piece of code should it be in the ‘subscription’ inside the route? or should I just include this as a helper or outside of a helper but in that same file. Not sure where to put this.
I haven’t looked at @arunoda 's code but I’m guessing this goes into the Templates created method. For example
Template.templateName.created = function () {
var template = this;
template.autorun(function() {
// Make user reactive so that it reloads after the userProfile
// subscription is ready.
var user = Meteor.user();
if(user) {
template.subscribe('something_about_the_user');
}
}
}
@robsw has a good point – if you use this.autorun inside a template’s created hook, the function is automatically stopped when the instance gets removed again.
(Note, in regard to user data, that all publications are automatically rerun whenever login status changes.)