Theme modifiers: A brief introduction


目录

As themes become more ambitious, we've been looking for ways to allow them to manipulate core server-side behavior. While they will never be given the same level as control as plugins, we can provide some predefined hooks for themes to manipulate.

Introducing: theme modifiers :partying_face:

They are specified using the modifiers key in your theme's about.json file.

For a 100% up-to-date list of modifiers, check the database schema at the bottom of theme_modifier_set.rb, but here's a quick summary of what we have so far:

One theme making heavy use of these new hooks is https://meta.discourse.org/t/topic-list-thumbnails-theme-component/150602?u=david - check out the code to see how it works.

Setting-dependent modifiers

Theme modifiers can also be configured to pull their value from a theme setting, allowing site operators to override modifier behavior without editing the theme's code. To make a modifier depend on a setting, use this syntax in your about.json:

{
  "modifiers": {
    "modifier_name": {
      "type": "setting",
      "value": "setting_name"
    }
  }
}

For example, if you have a theme setting called show_excerpts and want it to control the serialize_topic_excerpts modifier:

In settings.yml:

show_excerpts:
  default: false

In about.json:

{
  "modifiers": {
    "serialize_topic_excerpts": {
      "type": "setting",
      "value": "show_excerpts"
    }
  }
}

When the show_excerpts setting is changed, the modifier value will automatically update to match. This provides flexibility for site operators to customize theme behavior through the admin UI.


版本号 #2
由 壳壳虫 创建于 2026-10-31 13:31:15 UTC
由 壳壳虫 更新于 2026-10-31 13:31:16 UTC