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، وقد ذكر شخص ما في هذا المنشور أن روابط التنقل العلوية المخصصة يمكن أن تحل المشكلة:
ومع ذلك، لا يقوم هذا المكون بإنشاء روابط ديناميكية بناءً على الموقع الحالي للتحقق من عنوان 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 : "";
// القائمة الرئيسية وفئتان محددتان ستحتويان على عنصرَي تنقل هذين بعناوين 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؟
شكرًا!
هل لا يزال يعمل؟ لم ينجح الأمر عندما جربته، هل يجب أن نضيف إصدارًا من الإضافة؟

