Custom Hamburger Menu Links

I noticed this too and it seems to only the external links not appears under More.

2 Likes

I use internal links in this component, for example, I have a link that opens user invites: /my/invited/pending/

When opening the link from the sidebar I get: Oops! That page doesn’t exist or is private.

The link works when accessed from the URL bar.

When entering the full URL (https://domain.com/my/invited/pending/) the URL opens like this:
https://domain.com/https://domain.com/my/invited/pending/

2 Likes

Yep. Known issue.

2 Likes

Hello,
This is should work with: Chat,/chat/browse/open :slightly_smiling_face:

2 Likes

Yeah, I know. I sended my comment perhaps a little bit too fast. Well, defenetly too fast, because I should say there must use path instead full url.

Extra link for the chat… well, new sidebar changed the playground totally and it is not needed anymore.

2 Likes

I took a look at Discourse’s sidebar code and @nolo icons addition.

It seems that currently, it’s not possible to customize the icon’s custom links because the hamburger menu decoration method doesn’t take into account the prefixValue constant (which contains the icon’s name) or something like that…

It also seems to me that hamburger-menu decorations with api.decorateWidget are going to be depreciated. See:

Also, the fact that external links don’t work anymore could come from this:

So that there should be some changes in core to make this available.

:warning: My knowledge of how Discourse works is almost non-existent so I could be very wrong.

Am I right about my findings?

2 Likes

I’ve installed this theme component from github repo. running 3.0.0.beta15 on my discourse and even though I appear to have added it, the hamburger menu doesn’t show my link… Any ideas?

1 Like

It may be related to:

To this day, external links still don’t work.
And internal links must begin with a relative path, not a full path.

2 Likes

Thanks a lot for this useful component. I need to add a few important internal links, but now that the hamburger menu is integrated into the sidebar I find that they’re not very visible under the More menu. Users are usually terrible at finding things, so I really need to put them in the top level, ideally right after My posts. Are there any CSS hacks to accomplish this?

2 Likes

Beyond what CSS can achieve I think. The discourse team do have this on their roadmap, but it isn’t happening quickly (I think):

6 Likes

I use:

<script>
  const customHeader = document.createElement("div")
  customHeader.className = "sidebar-section-wrapper sidebar-section-community"
  customHeader.innerHTML = `
            <div class="sidebar-section-header-wrapper sidebar-row">
              <button id="ember11" class="sidebar-section-header sidebar-section-header-collapsable btn-flat btn no-text" type="button">
                <span class="sidebar-section-header-text"> Rechtliches </span>
              </button>
          </div>
          <div class="sidebar-section-content" id="customNavigation"/>
      `

  $(document).ready(function () {
    // Create the links
    const links = [
      { title: "Impressum", src: "/impressum" },
      { title: "Datenschutz", src: "/privacy" },
    ]

    // Mobile
    let hamburger = document.getElementById("toggle-hamburger-menu")
    if (hamburger) {
      hamburger.addEventListener("click", addCustomLinks)
    } else {
      addCustomLinks()
    }
    
    let bool = false;
    function addCustomLinks() {
      setTimeout(function () {
        // Force to wait until navigation has been loaded
        const sidebar = document.getElementsByClassName("sidebar-sections")[0]
        if (sidebar) {
          sidebar.append(customHeader)
          if (bool) return;
          // Get the customNav Id
          const customNavigation = document.getElementById("customNavigation")
          if (customNavigation) {
            links.filter(function (link) {
              let linkDiv = document.createElement("div")
              linkDiv.className = "sidebar-section-link-wrapper"
              linkDiv.innerHTML = `<a href="${link.src}" class="sidebar-section-link sidebar-section-link-everything sidebar-row ember-view">
                        <span class="sidebar-section-link-prefix icon"></span>
                        <span class="sidebar-section-link-content-text"> ${link.title} </span>
                    </a>
                  `
              customNavigation.append(linkDiv)
              let linkIcon = document.getElementById("link_" + link.title)
            })
          }
        }
        bool = true
      }, 0)
      
    }
  })
</script>

You can see the result at https://forum.courservio.de/
The original version of this code is from Add custom links to sidebar. Maybe it could help you.

5 Likes

@hosch Wow, very nice, exactly what I was looking for! Thanks very much.

1 Like

@hosch By any chance is it possible to move it higher up? I’d like it to appear after the Community section, or possibly even before it.


Edit: Looks like it’s possible with a variation on this:
Rearrange Existing Hamburger Menu Items - #3 by awesomerobot

.sidebar-sections {
  display: flex; /* Setup a flex layout so you can reorder things */
  flex-direction: column;
  .sidebar-section-community {
    order: -1;
  }
}

I wonder about moving it to the highest position?

There is a quirk with this method where the custom div disappears when toggling the visibility of the sidebar, for example if the browser window is narrow. This is a problem especially for tablets, which usually get the desktop version of Discourse and require clicking on the hamburger menu to display the sidebar. Any possible workarounds? Thanks!


Edit: Solved here: