# 插件与主题之间的拆分

**URL:** https://meta.discourse.org/t/splitting-between-plugin-and-theme/141895
**Category:** Development
**Created:** [2020年二月18日 13:38 UTC](https://meta.discourse.org/t/splitting-between-plugin-and-theme/141895 "2020-02-18T13:38:09Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![agmontpetit](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/agmontpetit/32/160109_2.png) [@agmontpetit](https://meta.discourse.org/u/agmontpetit)
#### Post date: [2020年二月18日 13:38 UTC](https://meta.discourse.org/t/splitting-between-plugin-and-theme/141895/1 "2020-02-18T13:38:09Z")

</div>

我们正在开发一个插件，用于在主题列表中序列化一个新属性（图片）（使用 `TopicListItemSerializer`）。然而，在常规的 Discourse 界面上下文中显示此图片并无意义。该图片将由我们自己的主题消费——这将使我们的站点与默认的 Discourse 安装大相径庭。

我最初的想法是创建一个仅提供该属性的插件，让主题负责消费并显示图片。这样做是否合理？还是说插件也应包含在界面中显示图片的代码？

---

<div class="post-metadata">

### Author: ![pmusaraj](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pmusaraj/32/119489_2.png) [@pmusaraj](https://meta.discourse.org/u/pmusaraj)
#### Post date: [2020年二月19日 14:01 UTC](https://meta.discourse.org/t/splitting-between-plugin-and-theme/141895/2 "2020-02-19T14:01:00Z")

</div>

您最初的想法没问题。将代码拆分为插件和主题，将为您提供灵活性，使您能够更新主题并更新网站，而无需重新部署（另一种方案是将所有 UI 代码放在插件中，这会在您进行更改时需要重新部署）。

---

<div class="post-metadata">

### Author: ![agmontpetit](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/agmontpetit/32/160109_2.png) [@agmontpetit](https://meta.discourse.org/u/agmontpetit)
#### Post date: [2020年二月19日 14:23 UTC](https://meta.discourse.org/t/splitting-between-plugin-and-theme/141895/3 "2020-02-19T14:23:56Z")

</div>

谢谢回复，@pmusaraj！
