# Display different content within a topic based on user's groups membership?

**URL:** https://meta.discourse.org/t/display-different-content-within-a-topic-based-on-users-groups-membership/227075
**Category:** Development
**Created:** [May 15, 2022, 12:01pm UTC](https://meta.discourse.org/t/display-different-content-within-a-topic-based-on-users-groups-membership/227075 "2022-05-15T12:01:25Z")
**Posts on this page:** 1
**Showing post:** 3

<div class="post-metadata">

### Author: ![jimkleiber](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jimkleiber/32/121814_2.png) [@jimkleiber](https://meta.discourse.org/u/jimkleiber)
#### Post date: [May 17, 2022, 7:15pm UTC](https://meta.discourse.org/t/display-different-content-within-a-topic-based-on-users-groups-membership/227075/3 "2022-05-17T19:15:14Z")

</div>

I don’t have too much time to dive into it right now but this theme component may help you because it’ll list all of the current user’s groups in, I think, the `body` tag. Then you could probably use CSS selectors to show/hide based on whether certain group class names exist in the `body` tag.

> [@CSS Classes for Current User's Groups](https://meta.discourse.org/t/css-classes-for-current-users-groups/226068):
>
> discourse2Summary CSS Classes for Current User’s Groups adds the groups that a member is a part of as CSS classes on the \<body\> tag.eyeglassesPreview [Preview on theme-creator.discourse.org](https://discourse.theme-creator.io/theme/Johani/user-groups-css-classes)hammer_and_wrenchRepository Link [https://github.com/discourse/discourse-groups-css-classes-in-body](https://github.com/discourse/discourse-groups-css-classes-in-body)open_bookNew to Discourse Themes? [Beginner’s guide to using Discourse Themes](https://meta.discourse.org/t/beginners-guide-to-using-discourse-themes/91966) Install this theme component Before: [image] After: [image] Discourse only adds the current us…

And combine that with some info from this post on how which HTML elements you can use in the composer and how to wrap composer text in classes, and it may work:

> [@What are the different ways to customize content inside a post (custom attributes and such)](https://meta.discourse.org/t/what-are-the-different-ways-to-customize-content-inside-a-post-custom-attributes-and-such/226747):
>
> So far I’m aware of two way to do it: \<span data-theme-custom\>some text\</span\> CSS: [data-theme-custom] { color: pink; } [wrap="indent"]some text[/wrap] It will create either a div or a span (if there is other content on the same line), containing the following attributes: class="d-wrap" and data-wrap="custom" CSS [data-wrap="custom"] { color: pink; } Are there other ways to customize some chosen content in a post I’m not aware of? Also, is there a way to add a custom c…

Yup, just tested it here and it should work if you use that component combined with something like:

```html
<span data-group-a>Text only for group A</span>
<span data-group-b>Text only for group B</span>

```

And then have css selectors that do something like:

```css
span[data-group-a] {display: none;}
body.group-a span[data-group-a] {display: block;}

```

Or something like that…

Sorry for all the edits. Just tested it on one of my instances and it works.

But as you mentioned, maybe that’s not what you wanted 🙂 …

> [@craigconstantine](#):
>
> But CSS `display: none` is weak sauce. I’d like to disappear from the DOM what they shouldn’t see. Disappeared server-side if possible, but I’d settle for at least j/s based disappeared browser-side. (That requires a much higher clever-level to get around than `display: none` does in CSS.)

This might be possible with a theme javascript, adding something in the `<head>` section to select the elements and remove it. Still may require the span and wrapping as above, but remove it through that.

---

_[View the full topic](https://meta.discourse.org/t/display-different-content-within-a-topic-based-on-users-groups-membership/227075)._
