Discourse has recently deprecated api.decorateWidget
, which I used to insert custom header icons and post the current user’s username via a URL.
I was wondering how I can post the user’s current username via HTTP with the new headerIcons
API. I couldn’t find any documentation or examples on how to implement this. I couldn’t find a way to do it via the Customer Header Link plugin either.
Appreciate your help! Below is my current code using the decorateWidget
API to post the username:
<script type="text/discourse-plugin" version="0.12">
const { iconNode } = require("discourse-common/lib/icon-library");
let icon = iconNode('calculator');
var currentUser = api.getCurrentUser();
var username = currentUser.username;
api.decorateWidget('header-icons:before', helper => {
const showExtraInfo = helper.attrs.minimized;
if(!showExtraInfo) {
return helper.h('li#calculator', [
helper.h('form#header-calculator.icon', {
action:'https://example.com/',
method:'post'
}, [
helper.h('button', {name:'u', value: username},[
iconNode('calculator'),
])
])
]);
}
});
</script>