I have the following template, which is loaded when a user clicks o the “Who osted this” button on a particular post.
<template name="profile">
{{#if existinguser}}
`//other code to render when esitinguser returns true//`
{{else}}
<p>This user doesn't exist.</p>
{{/if}}
</template>
Here’s is existinguser helper:
'existinguser': function() {
if (Meteor.users.find({
"profile.username": document.URL.split('/')[4]
}).count() > 0) {
return true;
} else {
return false;
}
}
And the route.js
Router.route('/user/:username', {
name: 'profile',
loadingTemplate: 'loading',
waitOn:function(){Meteor.subscribe('users');
},
data: function() {
return Meteor.users.find({
'profile.username': this.params.username
});
}
});
Now, when the link is clicked, the else block is rendered and the page says This user doesn’t exist, even though it is there in the Users
collection.
If I reload the page on the same url, it renders, and shows what ever there is inside the if block.
What might be the problem?