I want to add a topic to a top menu but not on all categories, just a specific one.
What code should I write?
Thanks
Found those topics but none of them was for a specific category…
https://meta.discourse.org/t/how-to-add-external-link-on-top-menu/9508/6
https://meta.discourse.org/t/best-way-to-customize-top-menu/35336
Tested this solution a bit more (modified from this post) try this (replace “Travel” with your category name):
<script>
Discourse.ExternalNavItem = Discourse.NavItem.extend({
href : function() {
return this.get('href');
}.property('href')
});
I18n.translations.en.js.filters.bugs = { title: "Bugs", help: "Open Bugs" };
I18n.translations.en.js.filters.google = { title: "Google", help: "Navigate to Google" };
Discourse.NavItem.reopenClass({
buildList : function(category, args) {
var list = this._super(category, args);
if(category && category.name == "Travel") {
list.push(Discourse.ExternalNavItem.create({href: '/category/bug', name: 'bugs'}));
list.push(Discourse.ExternalNavItem.create({href: 'https://google.com', name: 'google'}));
}
return list;
}
});
</script>
I18n.translations.en.js.filters.bugs = { title: “Bugs”, help: “Open Bugs” };
I18n.translations.en.js.filters.google = { title: “Google”, help: “Navigate to Google” };
Those are for English-based forums…
Your forum is French, so use I18n.translations.fr instead.
Still the same thing with translations.fr
<script>
Discourse.ExternalNavItem = Discourse.NavItem.extend({
href : function() {
return this.get('href');
}.property('href')
});
I18n.translations.fr.js.filters.liste = { title: "Liste", help: "Liste des formations" };
Discourse.NavItem.reopenClass({
buildList : function(category, args) {
var list = this._super(category, args);
if(category && category.name == "Formations") {
list.push(Discourse.ExternalNavItem.create({href: '/t/liste-2-0-des-formations-sur-lautosuffisance-et-la-consommation-ecoresponsable-en-2018/306', name: 'Liste'}));
}
return list;
}
});
</script>
Try name: 'liste'instead
Where has that lovely calendar come from??
Discourse.NavItem가 비추천(deprecated)된 이후 이 기능이 더 이상 작동하지 않는 것 같습니다. 이 게시물에서 누군가가 Custom top navigation links가 이 문제를 해결할 수 있다고 언급했습니다:
하지만 이 컴포넌트는 현재 위치를 기반으로 링크 URL을 확인하여 동적으로 링크를 설정하는 기능을 지원하지 않습니다.
제 사용 사례에서는 메인 페이지와 하위 카테고리별로 다른 링크를 설정하고 싶습니다. 예를 들어, 현재 카테고리에 따라 미완료/완료 태그 필터 내비게이션 항목을 표시하기 위해 다음 코드를 사용했지만, 이제 작동하지 않습니다:
<script>
Discourse.ExternalNavItem = Discourse.NavItem.extend({
href : function() {
return this.get('href');
}.property('href')
});
I18n.translations.en.js.filters.unfinished = { title: "tbc", help: "placeholder" };
I18n.translations.en.js.filters.finished = { title: "finished", help: "placeholder" };
Discourse.NavItem.reopenClass({
buildList : function(category, args) {
var list = this._super(category, args);
var url = category ? category.url : "";
// Main menu and 2 specific categories will have those 2 nav items with different url
if(!category || (category && url && (url.includes("mix") || url.includes("other")))) {
var tbc_url = category ? "/tags" + url + "/tbc" : "/tags/tbc";
var finish_url = category ? "/tags" + url + "/finished" : "/tags/finished";
list.push(Discourse.ExternalNavItem.create({href: tbc_url, name: 'tbc'}));
list.push(Discourse.ExternalNavItem.create({href: finish_url, name: 'finish'}));
}
return list;
}
});
</script>
현재 navigation-item 컴포넌트에 기반하여 이 코드를 어떻게 업데이트해야 하는지 도와주실 수 있을까요? 혹은 더 일반적인 질문으로, Discourse.NavItem의 대체 수단인 현재 사용 방법을 어떻게 찾을 수 있을까요?
감사합니다!
여전히 작동하나요? 제가 시도했을 때 작동하지 않았는데, 플러그인 버전을 추가해야 할까요?

