使用 decorateWidget 后,注册按钮不再显示

您好!看起来我们之前设置在登录按钮旁边的注册按钮不再显示了,并且我在控制台中看到一个错误:“[THEME NAME] decorateWidget: Could not find widget ‘header-buttons’ in registry”。

据我所知,直到现在添加此按钮的方式是通过“自定义”->“主题”并使用类似以下的脚本:

<script type="text/discourse-plugin" version='0.8.12'>
api.decorateWidget('header-buttons:after', function (helper) {
    if (!api.getCurrentUser()) {
        return helper.attach('link', {
            href: 'https://www.bassbuzz.com/account/signup',
            rawLabel: 'Sign Up',
            className: "btn btn-primary btn-small login-button"
        });
    }
});
</script>

我阅读了一些类似的主题,例如 https://meta.discourse.org/t/add-button-in-header-for-logged-in-users/276704/3,但我总是收到“header-icons”在注册表中未找到的错误。

我也尝试过以下方法,结果相同:

<script type="text/discourse-plugin" version='0.8.12'>
  api.decorateWidget('header-buttons:after', helper => {
    if (!api.getCurrentUser()) {
      return helper.h('li', [
        helper.h('a.btn.btn-primary.btn-small.login-button', {
          href: 'https://www.bassbuzz.com/account/signup'
        }, 'Sign Up')
      ]);
    }
  });
</script>

我还查看了这里的文档:https://meta.discourse.org/t/beginners-guide-to-developing-discourse-themes/93648,但我似乎无法弄清楚我缺少什么。

是否有任何设置可能阻止上述代码正常工作?它以前是有效的,我不确定是什么时候停止工作的。有人有什么建议吗?提前感谢!

您好 @Andreea_Pomirleanu :wave: 欢迎来到 meta :slight_smile:

decorateWidget 已被 Glimmer 组件弃用。请参阅此处了解详情:

https://meta.discourse.org/t/upcoming-post-menu-changes-how-to-prepare-themes-and-plugins/341014

请参阅下方正确的链接(感谢 RGJ)

1 个赞

这是另一个主题,Upcoming Header Changes - Preparing Themes and Plugins

1 个赞

您好 @RGJ,非常感谢您的快速回复!我会仔细阅读,如果还有其他问题,我会再联系您。