# 我能否使用我创建的主题而不允许他人使用？

**URL:** <https://meta.discourse.org/t/can-i-use-a-theme-i-created-without-allowing-it-to-be-used-by-others/176459>\
**Category:** Support\
**Created:** [2021年一月18日 15:48 UTC](https://meta.discourse.org/t/can-i-use-a-theme-i-created-without-allowing-it-to-be-used-by-others/176459 "2021-01-18T15:48:23Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![TheTechRobo](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/thetechrobo/32/192067_2.png) [@TheTechRobo](https://meta.discourse.org/u/TheTechRobo)\
**Post date:** [2021年一月18日 15:48 UTC](https://meta.discourse.org/t/can-i-use-a-theme-i-created-without-allowing-it-to-be-used-by-others/176459/1 "2021-01-18T15:48:23Z")

</div>

我创建了一个主题，但不希望普通用户使用它。

我可以不勾选“允许用户选择主题”来使用该主题吗？（我是管理员。）

---

<div class="post-metadata">

**Author:** ![simon](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/simon/32/339122_2.png) [@simon](https://meta.discourse.org/u/simon)\
**Post date:** [2021年一月18日 17:30 UTC](https://meta.discourse.org/t/can-i-use-a-theme-i-created-without-allowing-it-to-be-used-by-others/176459/2 "2021-01-18T17:30:02Z")

</div>

> [@TheTechRobo](#):
>
> 我可以在不选择“用户可选择主题”的情况下使用某个主题吗？（我是管理员。）

可以。进入该主题的编辑器，点击页面右下角显示的“预览”链接：

 ![image](https://global.discourse-cdn.com/meta/original/3X/c/2/c2fe2ca34d223e8541d6abcd1573188306628b77.png)

---

<div class="post-metadata">

**Author:** ![TheTechRobo](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/thetechrobo/32/192067_2.png) [@TheTechRobo](https://meta.discourse.org/u/TheTechRobo)\
**Post date:** [2021年一月18日 18:51 UTC](https://meta.discourse.org/t/can-i-use-a-theme-i-created-without-allowing-it-to-be-used-by-others/176459/3 "2021-01-18T18:51:47Z")

</div>

我的意思是作为主主题，即对我来说的主主题。不仅仅是预览，因为预览选项一旦从 URL 中移除，就会恢复到正常状态。

---

<div class="post-metadata">

**Author:** ![awesomerobot](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/awesomerobot/32/142900_2.png) [@awesomerobot](https://meta.discourse.org/u/awesomerobot)\
**Post date:** [2021年一月19日 02:38 UTC](https://meta.discourse.org/t/can-i-use-a-theme-i-created-without-allowing-it-to-be-used-by-others/176459/4 "2021-01-19T02:38:03Z")

</div>

管理员和版主在页面 `<body>` 上会被分配 `.staff` 类，因此你可以在主题中这样操作：

```scss
body.staff {
  // 你的管理员主题 CSS 代码放在这里
}

```

普通用户也可以通过浏览器开发者工具向其 `<body>` 标签添加 `staff` 类来查看该主题，但我不确定是否有人会费心去尝试这样做。

对于更高级的主题，如果你使用插件出口（plugin outlet）或通过模板覆盖来修改 HTML（参见 [Discourse 主题开发者指南](https://meta.discourse.org/t/developer-s-guide-to-discourse-themes/93648)），你可以这样做：

```hbs
{{#if currentUser.staff}}
  <h1>你好，管理员和版主！</h1>
{{/if}}

```

---

<div class="post-metadata">

**Author:** ![TheTechRobo](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/thetechrobo/32/192067_2.png) [@TheTechRobo](https://meta.discourse.org/u/TheTechRobo)\
**Post date:** [2021年一月19日 20:05 UTC](https://meta.discourse.org/t/can-i-use-a-theme-i-created-without-allowing-it-to-be-used-by-others/176459/5 "2021-01-19T20:05:55Z")

</div>

a) 我的主题中未使用任何 CSS，仅包含配色方案。  
b) 即便如此，仍需将该主题列为可用。

---

<div class="post-metadata">

**Author:** ![awesomerobot](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/awesomerobot/32/142900_2.png) [@awesomerobot](https://meta.discourse.org/u/awesomerobot)\
**Post date:** [2021年一月19日 20:14 UTC](https://meta.discourse.org/t/can-i-use-a-theme-i-created-without-allowing-it-to-be-used-by-others/176459/6 "2021-01-19T20:14:47Z")

</div>

> [@TheTechRobo](#):
>
> a) 我的主题中不使用任何 CSS，仅使用配色方案。

您可以使用 CSS 覆盖配色方案（详情参见：[https://meta.discourse.org/t/updating-themes-and-plugins-to-support-automatic-dark-mode/161595）。否则，您需要构建一个自定义插件，以便为管理员设置不同的主题，因为](https://meta.discourse.org/t/updating-themes-and-plugins-to-support-automatic-dark-mode/161595%EF%BC%89%E3%80%82%E5%90%A6%E5%88%99%EF%BC%8C%E6%82%A8%E9%9C%80%E8%A6%81%E6%9E%84%E5%BB%BA%E4%B8%80%E4%B8%AA%E8%87%AA%E5%AE%9A%E4%B9%89%E6%8F%92%E4%BB%B6%EF%BC%8C%E4%BB%A5%E4%BE%BF%E4%B8%BA%E7%AE%A1%E7%90%86%E5%91%98%E8%AE%BE%E7%BD%AE%E4%B8%8D%E5%90%8C%E7%9A%84%E4%B8%BB%E9%A2%98%EF%BC%8C%E5%9B%A0%E4%B8%BA) Discourse 本身尚无此功能。

> [@TheTechRobo](#):
>
> b) 这仍然需要将主题列为可用。

建议的做法是将管理员 CSS 放在您的默认主题中；除非有人深入查看您的 CSS 代码，否则只有您能看到并使用它。

另一种完全可行的方案是使用浏览器插件（如 [Stylish](https://chrome.google.com/webstore/detail/stylish-custom-themes-for/fjnbnpbmkenffdnngjfgmeleoegfcffe?hl=en)）在本地设置自定义 CSS。
