//THIS IS MY HELPERS AND EVENT HANDLERS FOR PF AND PC,COLLECTION NAME ROST
Template.pc.helpers({
p: function(){
return Rost.find({}, {sort:{created:-1}});
}
});
Template.pf.events({
'submit form': function(event){
event.preventDefault();
var content= document.getElementById('new').value;
var date= new Date(),
h=(date.getHours()<10?'0':'') +date.getHours(),
m=(date.getMinutes()<10?'0':'')+date.getMinutes();
var time=h+':'+m;
var username= Meteor.user().username;
Rost.insert({
content: content,
created:date,
time:time,
username: username
});
event.target.reset();
}
});
I am using meteor and mongo as DB where {{username}}, {{content}} and {{time}} are variables of object.
How can I access {{username}} using JavaScript?
its an group chat application …i needed the value of the {{username}} from pc template so that i can remove ‘message’ link for current user[one doesn’t message it self]and to make the posts of current user to float on the other side …for that i need to get value of {{username}} n then i have to compare that if username == curent user …then change the visibility of link ‘message’ to hidden and make that post float on other side –
thanks sir
its an group chat application …i needed the value of the {{username}} from pc template so that i can remove ‘message’ link for current user[one doesn’t message it self]and to make the posts of current user to float on the other side …for that i need to get value of {{username}} n then i have to compare that if username == curent user …then change the visibility of link ‘message’ to hidden and make that post float on other side –
That’s not the correct way of dealing with this kind of problem . There’s a better way - you create a helper to check you this message was sent by a current user (I assume that you have username stored in the profile field of your Meteor.users collection):