Include text at bottom of post for users in group


(Jay Pfaffman) #1

I’ve a client that wants to add a link to a user profile for members of a particular group.

I thought about the signature plugin, but I’m wondering whether it might be possible with a theme component.

Is there some way that in the :after of a post members of a certain group could have I'm great, see my [profile](https://site/u/username) in a theme component?


(Simon Cossar) #2

It could be done in a theme component with api.decorateWidget if the information you need about the user is available in the helper.attrs property that is passed to the function. This will work if the group you are looking for is the user’s primary_group.


(Jay Pfaffman) #3

Ooh. That sounds like what I’d hoped for. The group will be the primary group.

Can you give me another hint or two about just how api-decorateWidget works?


(Simon Cossar) #4

It can take a bit of messing around to find the right widget and type. The easiest way to do that is to look through the source code. Searching for applyDecorators in the widget files lets you know what types are available. The following works, but you should test it. Do a console.log on the attrs variable to see what is available to you. It will take a bit of CSS to get it to look good.

<script type="text/discourse-plugin" version="0.8.25">
   api.decorateWidget('post-contents:after-cooked', helper => {
       let h = helper.h,
           attrs = helper.attrs;
        if (attrs.primary_group_name === 'your_primary_group_name') {
            return h('div.group-signature', h('a.group-user-link',
                { href: '/u/' + helper.attrs.username }, 'See my profile!'));
        }
    });
</script>

(Jay Pfaffman) #5

Thanks a million, @Simon_Cossar. I really appreciate it. I’m still very novice at themes.

Here it is: GitHub - literatecomputing/discourse-theme-group-signature: Append text to posts of members of a particular group

I put the text of the link and the groups in theme settings. There is an alternate/second signature that has a customizable URL.

Is there a way to get a theme setting to use a selector, for example, the group selector?