Add button to top menu


(Patrick) #1

I want to add a button (with a different color) to the top menu, and if possible align right
How can i do this ?


#2

(Patrick) #3

Almost, but i want to have this button: Premium


#4

Check here: How to add header menu links


(Patrick) #5

check, did this but there is no button …


(Brendan Schlagel) #6

You’ll have to customize a bit with HTML / CSS to get exactly the look you’re going for. If you have a reference button you want to copy you can often get most of the way there by inspecting using something like Chrome web tools and copying existing styles. Lots of tutorials you can follow + modify as well! Definitely a bit of a learning curve but imo fun to figure out how this stuff works :slight_smile:


(cpradio) #7

Screenshots would be really helpful. It is hard to tell if your theme component is just not active or if you put the code in the wrong place.


#8

Show us what you’ve got so far and we’ll help you tweak it. We’re flying blind a bit here…


(Patrick) #9

this is the forum: https://forum.webwinkelcommunity.nl/
and instead of the bleu arrow icon i want a button with Premium (or Donateur)


(cpradio) #10

Try changing the following

    api.decorateWidget('header-icons:before', function (helper) {
        return helper.h('li', [helper.h('a#home-button.icon', {
            href: 'https://forum.webwinkelcommunity.nl/t/wordt-donateur/2171/1',
            title: 'Wordt Donateur'
        }, helper.h('i.fa.fa-arrow-circle-up.home-button-icon.d-icon'))]);
    });

to

    api.decorateWidget('header-icons:before', function (helper) {
        return helper.h('li', [helper.h('a#home-button', {
            href: 'https://forum.webwinkelcommunity.nl/t/wordt-donateur/2171/1',
            title: 'Wordt Donateur',
            text: 'Wordt Donateur'
        })]);
    });

With the following CSS

a#home-button {
    border: 1px solid #000;
    padding: 5px;
    border-radius: 3px;
    position: relative;
    display: block;
    margin-top: 5px;
}

Screenshot:
image


(Paul W) #11

This should do it: ( demo: https://www.mcrides.co.nz I have a “Weather” link )
You’ll need to style it with css.
customize->theme-></body

<script>

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

  I18n.translations.en.js.filters.premium = { title: "Premium", help: "Premium account" };

  Discourse.NavItem.reopenClass({
    buildList : function(category, args) {
      var list = this._super(category, args);
      if(!category) {
        list.push(Discourse.ExternalNavItem.create({href: '/my/link.html', name: 'premium'}));
      }
      return list;
    }
  });

 </script>

New top-menu item or drop-down
/about page add a new link and menu
Adding link to blog on main page
(cpradio) #12

But that adds it to the Navigation, not the header…

But I guess it isn’t obvious which he wants, as his initial posts says “top menu” which refers to the navigation, but his screenshot and example of where his icon is… is in the header.


(Paul W) #13

My example adds to header menu, not to navigation


(cpradio) #14

You are opening the NavItem class and your Weather example is on the navigation…


(Paul W) #15

oh :blush:

Maybe he wants

<script type="text/discourse-plugin" version="0.4">
api.decorateWidget('header-icons:before', helper => {
    return [
            helper.h('li', [
            helper.h('a#premium-button.icon', {
                href: '/link.html',
                title: 'Premium Content'
            }, helper.h('i.fa.fa-cloud.premium-button-icon.d-icon')),
        ])
    ];
});
</script>

(cpradio) #16

Close, that is almost what he has now, I provided code that puts text there and makes it more “button-ish” (just a few posts up) :wink: So now he has both … one of the two should do what he wants.


(Patrick) #17

Great @cpradio that works, many thanks!


(AppyBuilder) #18

Hi,

  1. How and where do you add the icons? I like to use external icons instead of fa
  2. I’m trying to open an external link. Is there a way to add a target so that we use a different window?

Thanks