# 关于分类自定义字段的问题

**URL:** https://meta.discourse.org/t/questions-about-category-custom-fields/86115
**Category:** Development
**Created:** [2018年四月25日 02:34 UTC](https://meta.discourse.org/t/questions-about-category-custom-fields/86115 "2018-04-25T02:34:13Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![Flower\_Child](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/flower_child/32/94987_2.png) [@Flower\_Child](https://meta.discourse.org/u/Flower_Child)
#### Post date: [2018年四月25日 02:34 UTC](https://meta.discourse.org/t/questions-about-category-custom-fields/86115/1 "2018-04-25T02:34:13Z")

</div>

hello!

i’m working on creating a simple plugin that allows a category to be assigned a font awesome icon. The icon will display instead of an image if one is not set.

I’m not really interested in doing it with a theme-specific hack like `:before` CSS because I’d like it to be something settable in the category settings panel - indeed I’ve already got that part working. Here’s my code so far:

plugin.rb

```ruby
# name: category-icons
# about: Allows fa-icons to be used as category graphics.
# version: 0.1
# authors: Flower_Child
# url: https://github.com/tipsypastels/category-icons

after_initialize do
  Category.register_custom_field_type('fa_icon', :string)

  add_to_serializer(:basic_category, :fa_icon) do
    object.custom_fields['fa_icon']
  end
end

```

assets/javascripts/discourse/connectors/category-custom-settings/fa-icon-settings.js.es6

```javascript
export default {
  setupComponent(args, component) {
    const category = args.category;

    if (!category.custom_fields) {
      category.custom_fields = {};
    }

    if (typeof args.category.custom_fields['fa_icon'] !== 'string') {
      args.category.custom_fields['fa_icon'] = '';
    }
  }
}

```

assets/javascripts/discourse/connectors/category-custom-settings/fa-icon-settings.hbs

```glimmer
<section class="field">
  <label>
    {{i18n 'fa_icon_categories.fa_icon'}}
    {{input type="text" value=category.custom_fields.fa_icon}}
  </label>
</section>

```

Those are all the files I have so far - I’ve tried adding more based on things I’ve seen in other plugins but haven’t made any headway. This bit works in the sense of adding a custom field to the category settings, and the value I enter into it persists, but I can’t actually make it display on the categories list page. Using `{{category.fa_icon}}` or `{{category.custom_fields.fa_icon}}` in a theme-specific customization to `categories-only.hbs` or other templates is just blank.

Does it take more than this to be able to use custom fields in a template? I’m not sure what I’m missing. Is there any resource for how to use these in detail?

---

<div class="post-metadata">

### Author: ![Flower\_Child](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/flower_child/32/94987_2.png) [@Flower\_Child](https://meta.discourse.org/u/Flower_Child)
#### Post date: [2018年四月29日 23:23 UTC](https://meta.discourse.org/t/questions-about-category-custom-fields/86115/2 "2018-04-29T23:23:28Z")

</div>

☹ ☹ ☹  
no one have any ideas? i havent made much progress. idk how the people who do make plugins are figuring stuff like this out when there’s no documentation on it.
