# Simple Script to Show / Hide Content Based on Group

**URL:** https://meta.discourse.org/t/simple-script-to-show-hide-content-based-on-group/74761
**Category:** Support
**Created:** [November 24, 2017, 8:43pm UTC](https://meta.discourse.org/t/simple-script-to-show-hide-content-based-on-group/74761 "2017-11-24T20:43:54Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![8BIT](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/8bit/32/76872_2.png) [@8BIT](https://meta.discourse.org/u/8BIT)
#### Post date: [November 24, 2017, 8:43pm UTC](https://meta.discourse.org/t/simple-script-to-show-hide-content-based-on-group/74761/1 "2017-11-24T20:43:55Z")

</div>

Maybe a little spot-check here…

I was given this for advertising:

```plaintext
<script src="//m.servedby-buysellads.com/monetization.js" type="text/javascript"></script>
    <script>
(function(){
    if(typeof _bsa !== 'undefined' && _bsa) {
        _bsa.init('fancybar', 'CKYDV2QM', 'placement:thebitcoinpub');
    }
})();
</script>

```

And I’d like to show this code to _everyone_ except those who are in the Group “[patrons](https://thebitcoin.pub/groups/patrons)” (using the Patreon Plugin).

Does this look right?

```plaintext
<script src="//m.servedby-buysellads.com/monetization.js" type="text/javascript"></script>
    <script>
const user = Discourse.User.current(); 
(function(){
    if ((typeof _bsa !== 'undefined' && _bsa && user === null) || typeof _bsa !== 'undefined' && _bsa && user !== null && user.primary_group_name !== "patrons") {
        _bsa.init('fancybar', 'CKYDV2QM', 'placement:thebitcoinpub'); }

    }
  }
})();
</script>

```

This doesn’t seem to give the result that I’m looking for… is there a better way of doing this?

Thanks in advance!

---

<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: [November 24, 2017, 9:09pm UTC](https://meta.discourse.org/t/simple-script-to-show-hide-content-based-on-group/74761/2 "2017-11-24T21:09:39Z")

</div>

```plaintext
<script type="text/discourse-plugin" version="0.8">
    var u = api.getCurrentUser();
    if (u !== null) {
        u.findDetails().then(function(u) {
            if (!u.groups.some((g) => g.name === 'patrons')) {

                // user isn't a patron, insert code here

            }
        });
    }
</script>

```

This will work, but will be an extra request on every page load.

---

<div class="post-metadata">

### Author: ![nixie](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/nixie/32/82174_2.png) [@nixie](https://meta.discourse.org/u/nixie)
#### Post date: [November 24, 2017, 9:13pm UTC](https://meta.discourse.org/t/simple-script-to-show-hide-content-based-on-group/74761/3 "2017-11-24T21:13:52Z")

</div>

@Falco

1. Can we insert even CSS code there?
2. This can be code-block can be pasted in the section - correct?

---

<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 18, 2020, 10:20pm UTC](https://meta.discourse.org/t/simple-script-to-show-hide-content-based-on-group/74761/4 "2020-01-18T22:20:46Z")

</div>



---

<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: [November 28, 2023, 1:23pm UTC](https://meta.discourse.org/t/simple-script-to-show-hide-content-based-on-group/74761/5 "2023-11-28T13:23:40Z")

</div>


