Include text at bottom of post for users in group

AI-generated summary

The discussion is about adding a link to a user profile for members of a particular group at the bottom of their posts. pfaffman initially considered using the signature plugin but opted for a theme component instead. simon suggested using api.decorateWidget to achieve this, which pfaffman found helpful.

simon provided a code example to get started with api.decorateWidget and suggested testing it with a console.log to explore available attributes. The example code checks the user’s primary group and adds a link to their profile if it matches the specified group.

pfaffman successfully created a theme component using simon’s example and made it available on GitHub. The theme component includes theme settings for the link text and groups, as well as an alternate signature with a customizable URL. pfaffman now wonders if it’s possible to use a theme setting with a selector, such as a group selector.

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?

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.

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?

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>

Thanks a million, @simon. 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 · GitHub

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?