Developing Discourse Plugins - Part 3 - Add custom site settings

You simply need to add a

config/locales/server.zh_CN.yml

file (and similar for any other locales you want to support) with the same English tokens but with language specific values and the plugin will use that instead of falling back to the English.

2 Likes

Thanks for helping! have a nice day!

3 Likes

I was looking how to create a site setting that validates a username, but found there’s a username type to do this. Here the list of site setting types we have today:

  • email
  • username
  • integer
  • regex
  • string
  • list
  • enum

Also, you can do custom validations for your plugin settings, it accepts a validator field that expects a Ruby class. You use it like this.

plugins:
  my_custom_username_validation:
    default: 'system'
    validator: 'UsernameSettingValidator'

You can check the UsernameSettingValidator class to see the interface of validators.

Cheers!

10 Likes

not working (

<a id="forgot-password-link" class="forgot-password" href="{{Discourse.SiteSettings.myplugin_link_forgot_password}}" target="_blank">Forgot password?</a>

settings.yml

plugins:
  myplugin_enabled:
    default: true
    client: true
  myplugin_link_forgot_password:
    default: ''
    client: true

upd:
working!!!
href="{{unbound siteSettings.myplugin_link_forgot_password}}"

how to display text html ?
not working {{unbound siteSettings.forum_text_for_admin}}

upd:
working in *.hbs {{{unbound siteSettings.forum_text_for_admin}}}

Again you need to use a Computed Property and format as safe html. This is EmberJS not vanilla JavaScript. You can’t put ‘code’ directly into templates. Read the ember guides.

1 Like

already working with EmberJS