I’m trying to make a theme component that overrides the user profile template based on the viewed user’s group membership. I’d like profiles for anonymous users to not show the #user-content area at all unless the currentUser is staff. I’ve made a group that anonymous users are automatically added to, but I’m having trouble conditionally overriding the template.
Based on Overriding Discourse Templates from a Theme and Adding background videos to certain user profiles I’ve been trying to override user/summary.hbs like this:
<script type="text/discourse-plugin" version="0.8">
const TARGET_GROUP = "anon"
api.registerConnectorClass('above-user-summary-stats', 'user-summary', {
setupComponent(args, component) {
const inGroup = [...args.model.groups].filter(g => g.name === TARGET_GROUP)
const isAnon = inGroup.length ? true : false;
component.setProperties({isAnon})
}
});
</script>
<script type="text/x-handlebars" data-template-name="user/summary">
<DSection @pageClass="user-summary" @tagName="">
<div class="user-content" id="user-content">
<PluginOutlet
@name="above-user-summary-stats"
@args={{hash model=this.model user=this.user}}
/>
{{log isAnon}}
</div>
</DSection>
</script>
This overrides the template for all profiles, but isAnon is undefined so I think I’m not understanding how to create the logic for handlebars to check when overriding instead of adding to a plugin outlet.
Is the registerConnectorClass correct to use for this? Is a template override necessary here? I’ve been through the plugin api and User.rb and I figured out how to check if the current user is in anonymous mode, but I didn’t find any easy access besides group to check if the viewed user is anonymous. I’m familiar with Rails, js, and handlebars but I’m new to Ember and Discourse.