How to add custom fields to models

Is it possible to add a custom field to tags using the same logic?


Has anyone applied this to groups? If so, can you share what you did?

I guess this would do the trick. Hopefully it’s still up-to-date.

No, tags don’t have custom fields. What are you trying to accomplish?

Yes, that repository should work. Just change all instances of my_field to the name of your field.

1 Like

I am trying to create the following plugin: Creating a User - Tag relation plugin

Is there some more documentation about how to customize these group fields? It works indeed great with this boilerplate code. But how to extend it properly?

I for example want to add a few input fields, like:

<div class="control-group">
  <label class="control-label" for="map">Chapter coordinates</label>
  <input name="chapter_coordinates" id="chapter_coordinates" class="ember-text-field ember-view input-xlarge" value={{group.custom_fields.group_coordinates}} placeholder="E.g. 52.3727598,4.8936041" type="text">
  <div class="control-instructions">Fetch coordinates from</div>

But I’m just guessing what to do here and then add the rest of the Discourse stuff. The example above is to use a field for coordinates. I intent to use the g.json to create a map based on the group metadata.

I also intend to add a checkbox for emailing the group with a mail setup for that group.

<div class="control-group">
  <label class="control-label" for="map">Contact chapter by email</label>
  {{input type="checkbox" checked=group.custom_fields.contact_group_by_email}}
  <span>{{i18n 'admin.groups.contact_group_by_email.label'}}</span>

However, this field is best placed in the interaction tab. How to know what to do to get it there? I would like to become more proficient with this. But I get the idea that this information is just in the code, not documented somewhere. Which is probably fine, but just takes more time and effort to find what I’m looking for. Although what I want to add is quite small, just a few fields to the groups :nerd_face:

Yes, it can be tricky and a bit overwhelming when starting to navigate the Discourse codebase. It sounds like you’re trying to work with GeoJSON. Have you considered using or extending the Locations Plugin? That’s already set up to work with GeoJSON in Discourse.

A course in plugin development?

I’ve been considering running a free course in discourse plugin development, which is essentially what you need. I’ve already written the course materials for a course in theme development (see below). If 30 people vote for one in plugin development I’ll write a give a course (via zoom) in it.

  • Write and give course in plugin development
  • Don’t write and give a course in plugin development

0 voters

Introduction to theme development
  1. GitHub - pavilionedu/discourse-theme-introduction
  2. GitHub - pavilionedu/discourse-theme-css
  3. GitHub - pavilionedu/discourse-theme-colors
  4. GitHub - pavilionedu/discourse-theme-html-one
  5. GitHub - pavilionedu/discourse-theme-html-two
  6. GitHub - pavilionedu/discourse-theme-javascript-one
  7. GitHub - pavilionedu/discourse-theme-javascript-two

*ps if it hits 30 please let me know.


Awesome! I actually will use a fork of this Fairphone community map. They use the raw YAML output of a topic. I’ve modified my fork to use the data from g.json to draw markers on the map. I just miss a few fields such as coordinates and a boolean to use an email address in the map. Maybe some more, but first I’ll need to know how things work. Thanks for the links! Will have a look this week and see how far I’ll get. A course would be awesome too! My JS/Ruby skills are now though. Mainly Python/Bash and some crumbs from other language’s.

Is it possible to add custom fields to posts? Ideally from the post composer.

What is the minimum discourse version required to use this plugin?

Is this GitHub - pavilionedu/discourse-group-custom-fields still up to date?

The reason I ask is because I attempted to implement a new custom group field, but it doesn’t seem to be saving/persisting the value I enter into the input field after clicking Save.

Here’s the commit with all of the changes I did that (I think) correctly followed the edu repo’s structure: add discord_role_id field to groups · aloha-pk/discourse-discord-sync@fd3eef1 · GitHub

Yes, I just tested it and it’s working as expected.

{{input type="text" checked=group.custom_fields.discord_role_id}}

Your issue is that you’ve changed the input type to text, but left the value input as checked. You need to change checked to value.


Welp, that’ll do it :man_facepalming: Thanks for the help! :smile:

1 Like

Was just able to rebuild with this change, but unfortunately am still seeing the same issue. The value I entered gets cleared out after I save and re-load the page.

Any other suggestions @angus?

Did you change anything else from the example? The example works. Try starting with the example itself. If that’s also failing in your environment, then something else is going on. If the example works in your environment, then progressively work through the changes you made until you find the one that’s breaking it.