AstonJ
(AstonJ)
November 19, 2019, 5:09pm
1
I use this code (in the /head tab of the edit CSS/HTML customisation page) to add some additional items to the menu, however it’s stopped working after a recent update - anybody know why?
<script>
Discourse.ExternalNavItem = Discourse.NavItem.extend({
href : function() {
return this.get('href');
}.property('href')
});
I18n.translations.en.js.filters.first_name_here = { title: "Name", help: "Name again" };
I18n.translations.en.js.filters.second_name_here = { title: "Name", help: "Visit our...." };
I18n.translations.en.js.filters.tags = { title: "Tags", help: "Tags" };
Discourse.NavItem.reopenClass({
buildList : function(category, args) {
var list = this._super(category, args);
if(!category) {
list.push(Discourse.ExternalNavItem.create({href: 'http://forum.com/tags', name: 'tags'}));
list.push(Discourse.ExternalNavItem.create({href: 'https://forum.com/something', name: 'name'}));
list.push(Discourse.ExternalNavItem.create({href: 'https://forum.com/t/thread-url/193454#heading--name', name: 'name'}));
}
return list;
}
});
</script>
1 Like
Johani
(Joe)
November 19, 2019, 5:28pm
2
AstonJ:
Discourse.NavItem
does not exist in core anymore. If you want to add items to the top nav menu, you can use this component
This is a theme component that will allow you to add links to Discourse top navigation.
Screenshot:
Desktop
[Capture]
Mobile
[Capture]
Settings:
A navigation link needs three things
Name
Description
Path or URL
Name is the text for the link that shows up on the menu. Description shows up when you hover the name like this:
[hover2]
Path/URL is where you want the link to go.
You can add links as semicolon delimited values in theme settings following this order
name;description;URL …
7 Likes
AstonJ
(AstonJ)
November 19, 2019, 8:13pm
3
Thanks Joe - added!
Only thing is it seems to be stripping out the #jump to?
forum.com/t/thread-url/193454#heading--name
Edit: it seems it’s there and if you copy and pate the URL it works fine, but clicking on it in the nav, it gets stripped out and you just go to the top of the topic. Any ideas why?
1 Like
Falco
(Falco)
November 19, 2019, 10:01pm
4
5 Likes
AstonJ
(AstonJ)
November 19, 2019, 11:28pm
5
Thanks Rafael, I’m pretty sure it used to work so I’m guessing it’s a recent change…
1 Like
Johani
(Joe)
December 8, 2019, 5:01am
6
This was tricky to track, but @joffreyjaffeux added a fix for that here
https://github.com/discourse/discourse/commit/c5140ef3fb3146eb5a580beda254ae2bf4b6002c
It should work if your Discourse is up to date.
5 Likes
AstonJ
(AstonJ)
December 8, 2019, 6:06am
7
Fantastic - it works!!!
Thank you @Johani and @joffreyjaffeux
2 Likes
system
(system)
Closed
January 7, 2020, 6:13am
8
This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.