I want to customize UI based on the users group membership

I don’t really know at what version of Discourse the primary-group class for the current user started to be added as a class to the <body> tag

@fefrei was most likely correct there.

however,

your questions here was more directed towards CSS:

Which would be very, very different from not sending the content to the client. CSS hides stuff, but it does not mean it’s not there if you really look for it.

So, in regards to the question I answered, the answer is still yes.

based on the user’s primary group, you can in fact hide or show CSS classes.

here’s an example from another post here on meta:


Discourse adds a primary-group-GROUP_NAME class which you can use.

For example, if a user’s primary group is Car Owners, here’s what gets added to the <body> tag:

This class can then be selected with a CSS selector like:

.primary-group-car_owners

because the primary group class is added very early on in the cascade - to the <body> tag, you can use it as a base for cascading selectors very easily.

for a very exaggerated example, if you have a group called no emoji, and it’s set as the user’s primary group, and you add this to your theme:

.primary-group-no_emoji .emoji {
	display: none;
}

Then, members of the no emoji group will never see emojis because all emojis would be hidden from them with CSS.

`

5 Likes