How do we add buttons next to the "New Topic" button?

Is there an API to add new buttons next to or underneath the New Topic button - or where the New Topic button would go if logged out? I’d like to create an “Action” button with similar functionality to the Categories Button; when a user clicks it a dropdown should appear

I could definitely do it with jQuery, but I’d like to be able to switch out themes

image


This is the script I’m currently using to add a button to the very top menu, which I put in my themes common/head_tag.html:

image

<script type="text/discourse-plugin" version="0.4">
  api.decorateWidget('header-icons:before', helper => {
      return [
        helper.h('li', [
            helper.h('a.handsfree-show-when-stopped.handsfree-start.icon', {
                title: 'start webcam and enable handsfree'
            }, helper.h('i.fab.fa-video.home-button-icon.d-icon')),
        ]),
        helper.h('li', [
            helper.h('a.handsfree-show-when-started.handsfree-stop.icon', {
                title: 'stop webcam and disable handsfree'
            }, helper.h('i.fab.fa-video.home-button-icon.d-icon')),
        ])
      ]
  });
</script>

Is there something like that but for the New Topic section?

You’d want to use a plugin-outlet for this, discovery-list-container-top would work.

<script type="text/x-handlebars" data-template-name="/connectors/discovery-list-container-top/custom-name"> 
  <button> your button here </button>
</script>

It would just take a bit of additional CSS to align it to the right instead of the left.

There’s more on handlebars templates and plugin outlets in Developer’s guide to Discourse Themes

7 Likes

Thanks, that’s perfect!

2 Likes

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.