# 分类图标

**URL:** https://meta.discourse.org/t/category-icons/104683
**Category:** Theme component
**Tags:** official, deprecated, category-icons
**Created:** [2018年十二月19日 16:22 UTC](https://meta.discourse.org/t/category-icons/104683 "2018-12-19T16:22:44Z")
**Posts on this page:** 1
**Showing post:** 88

<div class="post-metadata">

### Author: ![oca](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/oca/32/156060_2.png) [@oca](https://meta.discourse.org/u/oca)
#### Post date: [2020年七月4日 09:24 UTC](https://meta.discourse.org/t/category-icons/104683/88 "2020-07-04T09:24:45Z")

</div>

我已经制作了一个[主题组件](https://meta.discourse.org/t/theme-component-to-use-category-icons-in-events-plugin-calendar/156766)，用于在 Events 插件的日历视图中添加图标。

它使用了 `category-icon` 小部件，但该小部件不会为子类别显示图标。因此，我不得不以这种方式添加一个“强制模式”：

```plaintext
  api.createWidget("category-icon", {
    tagName: "div.category-icon-widget",
    html(attrs) {
      let iconItem = getIconItem(attrs.category.slug);
      let force_display = ('force_display' in attrs);
      if(iconItem && (!attrs.category.parent_category_id || force_display)) {
        let itemColor = iconItem[2] ? `color: ${iconItem[2]}` : "";
        let itemIcon = iconItem[1] != '' ? iconNode(iconItem[1]) : "";
        return h("span.category-icon", { "style": itemColor }, itemIcon);
      }
    }
  });

```

您是否知道有没有办法在不使用这种“hack”的情况下实现相同的效果？  
如果没有，您是否考虑将其直接添加到代码中？

提前感谢。

---

_[View the full topic](https://meta.discourse.org/t/category-icons/104683)._
