如何在 outlet connector hbs 中访问用户数据?

I am working on a plugin that has to render a notice to some specific users in the top area of the website where notices show up. The plugin outlet that I am trying to override is:
{{plugin-outlet name="top-notices" tagName="" args=(hash currentPath=router._router.currentPath)}}

I am able to get a static version of the connector to work. I created the following file at this path: plugins/discourse-user-throttle/assets/javascripts/discourse/templates/connectors/top-notices/throttle_info.hbs



This line is working file. But the username does not show
{{{user.username}}}

The issue I am facing is that the {{{user.username}}} doesn’t username. How can that be done?

I found out using console log that the user is accessible as currentUser:

{{{currentUser.displayName}}}

1 个赞

您好,关于如何查看 currentUser 的属性,有什么指导吗?我似乎无法弄清楚如何或在哪里可以记录/查看它。我想访问 currentUser 的姓名并在我的页面上显示它。

您好,

如果您是指如何在模板中记录数据,可以使用 {{log data_here}},这应该会在浏览器控制台中显示。

您也可以使用 API:api.getCurrentUser()
例如,在您的主题/组件的 HTML \u003chead\u003e 中:

<script type="text/discourse-plugin" version="0.8">
  console.log(api.getCurrentUser());
</script>
1 个赞