Adding functionality to certain rooms only

Chat rooms for mChat with optional password protection
Post Reply
nou nou
Donor
Posts: 32
Joined: 10 Oct 2017, 19:38

Adding functionality to certain rooms only

#1

Post by nou nou » 09 Nov 2017, 18:12

Hello,


I would like to add a button to mChat (an image uploader) but only in certain rooms. What would the correct HTML if statement be for putting in the template/event?

i.e. if room ID = 1 then, or if room name is not lobby, then...

Thanks!

(or is there a better way to do this?)

User avatar
kasimi
mChat developer
Posts: 369
Joined: 06 Oct 2016, 09:56
Contact:

Re: Adding functionality to certain rooms only

#2

Post by kasimi » 09 Nov 2017, 20:05

Where exactly do you want to add the button? Right next to the room name? Try this code in mchatrooms_rooms.html:

Code: Select all

{% if mchatroom.ID == 1 %} ... {% endif %}
{% if mchatroom.NAME == 'Lobby' %} ... {% endif %}
If you want it displayed outside of the rooms list, for example next to the BBCode buttons, the best approach would be to hide the button when switching to a room where the functionality isn't supposed to be available, but that requires more code than just an IF.

nou nou
Donor
Posts: 32
Joined: 10 Oct 2017, 19:38

Re: Adding functionality to certain rooms only

#3

Post by nou nou » 10 Nov 2017, 01:31

OK thanks!

Why would that be the best approach, if you don't mind me asking?

User avatar
kasimi
mChat developer
Posts: 369
Joined: 06 Oct 2016, 09:56
Contact:

Re: Adding functionality to certain rooms only

#4

Post by kasimi » 10 Nov 2017, 09:13

It's the only possible way because the mchatroom variable in the code block above is only available inside that file. It really depends on where you want to add the button.

nou nou
Donor
Posts: 32
Joined: 10 Oct 2017, 19:38

Re: Adding functionality to certain rooms only

#5

Post by nou nou » 10 Nov 2017, 14:59

Ah - understood, thanks!

User avatar
kasimi
mChat developer
Posts: 369
Joined: 06 Oct 2016, 09:56
Contact:

Re: Adding functionality to certain rooms only

#6

Post by kasimi » 10 Nov 2017, 22:50

You could of course loop over all rooms again, anywhere you want:

Code: Select all

{% for mchatroom in loops.mchatroom %}
    <!-- here you can use the IFs from above -->
{% endfor %}
But again, that would require more code, for example to exclude rooms for users without see/use/etc permissions.

Post Reply

Who is online

Users browsing this forum: No registered users and 2 guests