我正在开发一个插件,需要向特定用户渲染一条通知,显示在网站上出现通知的顶部区域。我试图覆盖的插件出口是:
{{plugin-outlet name="top-notices" tagName="" args=(hash currentPath=router._router.currentPath)}}
我已经能够让连接器的静态版本正常工作。我在以下路径创建了文件:plugins/discourse-user-throttle/assets/javascripts/discourse/templates/connectors/top-notices/throttle_info.hbs
这行代码工作正常。但用户名没有显示
{{{user.username}}}
我遇到的问题在于 {{{user.username}}} 没有显示用户名。该如何实现?
我发现通过控制台日志可以访问用户信息,当前用户为 currentUser:
{{{currentUser.displayName}}}
bchoi28
(Brandon Choi)
3
您好,关于如何查看 currentUser 的属性,有什么指导吗?我似乎无法弄清楚如何或在哪里可以记录/查看它。我想访问 currentUser 的姓名并在我的页面上显示它。
您好,
如果您是指如何在模板中记录数据,可以使用 {{log data_here}},这应该会在浏览器控制台中显示。
您也可以使用 API:api.getCurrentUser()。
例如,在您的主题/组件的 HTML \u003chead\u003e 中:
<script type="text/discourse-plugin" version="0.8">
console.log(api.getCurrentUser());
</script>