Check for group membership in Header code?

The answer is yes, but the amount of work varies.

By calling

var user = Discourse.User.current();

You can get access immediately to their primary_group_name, but it won’t provide you with all groups they have access to.

To get all groups, you might have to do a call to /u/username.json and read the groups property. That makes it a tad more difficult as now you are awaiting the response of a call before you can show the link.

3 个赞