# Conditional header text based on group membership

**URL:** https://meta.discourse.org/t/conditional-header-text-based-on-group-membership/123348
**Category:** Development
**Created:** [July 18, 2019, 9:04pm UTC](https://meta.discourse.org/t/conditional-header-text-based-on-group-membership/123348 "2019-07-18T21:04:10Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![Cardinalflyer](https://avatars.discourse-cdn.com/v4/letter/c/f14d63/32.png) [@Cardinalflyer](https://meta.discourse.org/u/Cardinalflyer)
#### Post date: [July 18, 2019, 9:04pm UTC](https://meta.discourse.org/t/conditional-header-text-based-on-group-membership/123348/1 "2019-07-18T21:04:10Z")

</div>

I am hoping for some header / CSS help. I know a lot of languages but am just getting started with CSS.

I am trying to place a notice at the top of my header reminding members to renew when they get close to their renewal date. Renewal will be done via our main website, so I’d like to include a link. I am using the ‘Light’ theme.

I am very close, having taking the following steps:

1. Created a group called ‘renewal’ with a ‘please renew’ avatar but no other actions.

2. Set ‘renewal’ to be the primary group.

3. Included ‘renewal’ in the group ownership using SSO from my remote site based on renewal date.

4. Placed the following custom code in the Header of Common:

 ![image](https://global.discourse-cdn.com/meta/original/3X/c/4/c400b5b1e1545270b995f34b9778e86eebe3003f.png)

1. Placed the following code in the CSS of Common

 ![image](https://global.discourse-cdn.com/meta/original/3X/f/4/f4f2a00229c92e77c90b271b87ba90d594b013b8.png)

It works to the point of showing the text when the user is a member of the renewal group.

Now I’d like to enhance this notice by making it a red font and including an \<a tag for ‘click here to renew.’ But as most of you know, one cannot add HTML tags to a Content: string. I tried adding a font color to the \<div but no luck.

Is there an easy answer? Or another way completely to address this, like turning on and off the entire div block?

FYI the example I started from used a \<p tag in the header but that put an extra blank line at the top of the header whether triggered or not. I’d like to avoid that…

Thanks for your help!

---

<div class="post-metadata">

### Author: ![Falco](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/falco/32/179432_2.png) [@Falco](https://meta.discourse.org/u/Falco)
#### Post date: [July 18, 2019, 9:11pm UTC](https://meta.discourse.org/t/conditional-header-text-based-on-group-membership/123348/2 "2019-07-18T21:11:58Z")

</div>

I made a simple theme-component that puts group CSS classes in the html body for easy customizations, I call it [GitHub - discourse/discourse-groups-css-classes-in-body · GitHub](https://github.com/discourse/discourse-groups-css-classes-in-body/) 😅

That way you can create the entire banner in the HTML on the header and hide/show it based on the classes in the body.

---

<div class="post-metadata">

### Author: ![Cardinalflyer](https://avatars.discourse-cdn.com/v4/letter/c/f14d63/32.png) [@Cardinalflyer](https://meta.discourse.org/u/Cardinalflyer)
#### Post date: [July 18, 2019, 11:29pm UTC](https://meta.discourse.org/t/conditional-header-text-based-on-group-membership/123348/3 "2019-07-18T23:29:22Z")

</div>

Thanks @Falco. That is in the ballpark! My challenge is how to use that capability. In that component you say:

> After installing this component to the active theme you can target CSS using group membership like, for example:
> 
> body.group-patrons div.donation-banner {  
> display: none;  
> }

I know it is probably simple, but I am trying to understand that example. If I have a header div block like this:

```
<div name="test">My Text</div>

```

Then can I turn on that text when a class exists? Specifically something like:

```
.primary-group-renewal div.test {
   display: inline;
 }

```

And wouldn’t I also need to shut it off when that class does not exist? In fact isn’t the shutting off part the important bit? So perhaps something like this:

```
:not(.primary-group-renewal) div.test{
    display: none;
  }

```

I have been experimenting and googling but have not found this yet. I’m starting to watch the ‘about CSS’ youtubes which is probably good for me, but so far no hard clues. I appreciate your help!

---

<div class="post-metadata">

### Author: ![Cardinalflyer](https://avatars.discourse-cdn.com/v4/letter/c/f14d63/32.png) [@Cardinalflyer](https://meta.discourse.org/u/Cardinalflyer)
#### Post date: [July 19, 2019, 12:47am UTC](https://meta.discourse.org/t/conditional-header-text-based-on-group-membership/123348/4 "2019-07-19T00:47:48Z")

</div>

I’ve done a lot of experimentation and right now this is working, but I do have a question.

In Header:

```
<div id='renew' class='renewlink' align="center">
    <a href="https://www.example.com/renewlink" target="_blank")
    <font color='red'>
    Please click to renew your membership
    </font>
    </a>
</div>

```

In CSS:

```
.renewlink{
    display: none;
  }

.primary-group-renewal .renewlink{
    display: block;
  }

```

I really expected this to work instead of the double CSS entry above and it did not. What am I missing here?

```
:not(.primary-group-renewal) .renewlink{
    display: block;
  }

```

Thanks

---

<div class="post-metadata">

### Author: ![system](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/system/32/443519_2.png) [@system](https://meta.discourse.org/u/system)
#### Post date: [January 11, 2023, 2:27pm UTC](https://meta.discourse.org/t/conditional-header-text-based-on-group-membership/123348/5 "2023-01-11T14:27:05Z")

</div>


