你好!
我正在尝试创建一个主题组件,该组件将一个自定义按钮添加到已标记的主题中。例如:标记为 event-tag 的主题将在类别旁边显示一个名为 Event 的按钮,该按钮将链接到事件页面。
我通过本指南找到了希望添加按钮的位置(通过插件出口 topic-category):Developing Discourse Themes & Theme Components
我现在有这个:
<script type="text/x-handlebars" data-template-name="/connectors/topic-category/foobar2">
<div style="height: 25px; width: 25px;background: red">
<a href="<events_URL>" target="_blank">Link</a>
</div>
</script>
所以我的问题是,我如何检查主题的标签列表以查看上述脚本是否应添加按钮?
2 个赞
好的,取得了一些进展:
我发现如果我像这样使用 modifyClass:
<script type="text/discourse-plugin" version="0.8">
api.modifyClass("component:topic-category", {
didInsertElement: function() {
this._super();
console.log("Welcome to the topics page!")
}
});
</script>
我可以进入主题页面并得到“欢迎”的响应,但我仍然不确定如何提取 当前 页面的标签来判断是否应填充按钮。
1 个赞
啊,我找到了解决方案。
我一直在重读这个:Developing Discourse Themes & Theme Components
并发现如果我只 console.log(this),它就能输出页面上的所有数据,包括标签。我想我现在可以从这里开始,提取页面上的标签数据,并检查它是否在设置中。一旦我打磨好它,认为它已准备好公开发布,我就会在主题组件类别中发布它。只是想分享我的发现,以防其他人也在学习如何制作主题组件!
3 个赞
Canapin
(Coin-coin le Canapin)
4
仅供参考,在此上下文中获取标签列表的代码将是:
<script type="text/discourse-plugin" version="1.4.0">
api.modifyClass("component:topic-category", {
pluginId: "returnTags",
didInsertElement: function() {
this._super();
console.log(this.topic.tags)
}
});
</script>
返回:
(pluginId is required to avoid a warning)
1 个赞