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

AI-generated summary

user1 asks how to add a button next to or beneath the ‘New Topic’ button using an API, preferably theme-compatible. They currently use a script in head_tag.html to add a button to the top menu. user2 suggests using a plugin outlet, specifically discovery-list-container-top, with a handlebars template to insert the button, noting that CSS adjustments may be needed for alignment. user1 thanks for the solution.

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


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 Developing Discourse Themes & Theme Components

Thanks, that’s perfect!