0

I am using nodejs and socket to create chat application. I am able to show connected users list. I am showing all connected users list using following code.

 {{#each users}}
 <li><b>{{this.username}}</b></li>
 {{/each}}
 </ul>

Now i don't want to show current user in that list. If someone can help me to sort out this then it will great.

Kishor
  • 356
  • 2
  • 11
  • 1
    Your code has to pass the template a `users` object (or a copy of it) that has the current user already removed. This is something you have to solve in your Javascript code that prepares the data for the template, not in your template. – jfriend00 Oct 26 '15 at 06:42
  • Either remove current user from `users` list or use `if` condition in each loop where you will check for current user. If current user found, then do nothing else display username. Refer http://stackoverflow.com/questions/8216918/can-i-use-conditional-statements-with-ejs-templates-in-jmvc – Gaurav Gupta Oct 26 '15 at 06:44
  • @GauravGupta: Yeah I know theoretically i have to do that but actually i am a learner of nodejs so, i cannot do that easily.. – Kishor Oct 26 '15 at 09:50

1 Answers1

0

In your javascript code, remove the current username from 'users' array :

users.splice(users.indexOf(currentUser,1),1)

now render users to the the template!

user2473779
  • 711
  • 6
  • 18