Add custom anonymous mode button

This can be done by using a plugin outlet and adding some handlebars (these concepts are covered in Developer’s guide to Discourse Themes)

In your theme (admin > customize > themes > edit CSS/HTML), you can add this to your </head> file.

<script type="text/x-handlebars"  data-template-name="/connectors/above-main-container/anon-button">
{{#if this.currentUser}}
  {{#if this.currentUser.is_anonymous}}
    {{d-button class="btn-primary" action=(route-action 'toggleAnonymous') icon="ban" label="switch_from_anon"}}
  {{else}}
    {{d-button class="btn-primary" action=(route-action 'toggleAnonymous') icon="user-secret" label="switch_to_anon"}}
  {{/if}}
{{/if}}
</script>

Screen Shot 2019-12-12 at 2.03.57 PM

10 Likes