Add button to top navigation bar

(Kgish) #1

I’m developing a plugin which needs to be able to append an extra button to the top navigation bar:

list-controls > .container > div > .ul.nav

I also need to remove the new-topic button at the far right.

What is the proper way to do this? Plugin.rb? Javascript?

How to add a topic in top nav in a specific category?
(cpradio) #2

You could hide the New Topic button via CSS and to add navigation you can do that in the Customize JavaScript sections. See the below post as an example (there are others in that topic too)

(Kgish) #3

CSS will not work, so I resorted to the following solution which I happed to find elsewhere on the forum:

Discourse.ExternalNavItem = Discourse.NavItem.extend({
    href : function() {
        return this.get('href');

// Add navigation button 'Mijn berichten'

    buildList : function(category, args) {
        console.log(`NavItem#buildList(), category="${category?category.get('name'):'null'}", args="${JSON.stringify(args)}"`);
        var list = this._super(category, args);
        if (!category && args.filterMode !== 'posted') {
            console.log('NavItem#buildList() => add posted button ');
            list.push(Discourse.ExternalNavItem.create({href: '/posted', name: 'posted'}));
        return list;

(cpradio) #4

It should for hiding the New Topic button, but for adding links, you are correct, it won’t which is why I linked to that topic (to show you how to add buttons)