如何在discourse论坛中特定主题的主题正文下添加唯一的HTML内容

this.model 包含主题数据,例如 idtitle 等。你可以使用它。

例如,要允许主题 ID 90 或 38,你可以这样写:

<script type="text/x-handlebars" data-template-name="connectors/topic-area-bottom/custom-html">
  {{#if (or (eq this.model.id 90) (eq this.model.id 38))}}
    <div class="banner-control">
      <!-- Unique HTML content goes here -->
    </div>
  {{/if}}
</script>

不过,我建议你使用 Theme CLI 并使用 split files

在那里添加更多条件或进行一些逻辑处理会很困难。可以使用 registerConnectorClass,但它已弃用。

现代方法是使用 renderInOutlet 和一个 glimmer 组件——例如,https://github.com/discourse/discourse-custom-header-links。
你说你想在特定的 outlet 中渲染:

你在这里定义了模板。请注意 this.shouldShow
https://github.com/discourse/discourse-custom-header-links/blob/main/javascripts/discourse/components/custom-header-links.hbs#L1

然后你可以在这里添加你的逻辑,来告诉组件是否显示:
https://github.com/discourse/discourse-custom-header-links/blob/main/javascripts/discourse/components/custom-header-links.js#L5-L7

希望这有帮助。如果你需要更多帮助,请告诉我。 :+1:

5 个赞