Showing simple text with decorateWidget

AI 生成的摘要

Radulf is developing a Discourse plugin to display text after a poster’s name using the decorateWidget method. However, they are struggling to find documentation on the method and its h helper. eviltrout suggested that returning a string instead of using the h helper should solve the issue, which Radulf confirmed works. Additionally, Radulf inquired about marking an answer as “Solved” and vinothkannans explained that the “Solved” button is only available in the Support category on Meta.

Hi

I started developing plugins for Discourse this week. I already finished my first one, that adds a button below each post that links to a homepage, depending on the post. Now, I’m on to my second project and I merely want to show some text after the name of the poster. It seems like decorateWidget is a nice way to go there, but I don’t know how I get that to work. By basic copy + pasting, I was able to show a small icon, but simply showing text still eludes me. Here’s my current code of the initializer:

import { withPluginApi } from 'discourse/lib/plugin-api'

function initializePlugin(api) {
  console.log(api)

  api.decorateWidget('poster-name:after', function(helper) {
    return helper.h('i.fa.fa-arrow-circle-up.home-button-icon');         
  });

}

export default {
  name: 'youtrack-button',
  initialize: function() {
    withPluginApi('0.1', api => initializePlugin(api))
  }
}

Especially the decorateWidget part is merely copy + paste that I simplified a bit. Unfortunately I did not find any documentation for decorateWidget or h, which would probably solve these basic questions. So, how would I need to change the code to show the content of some string behind the name?

Thanks for your help!

Please see Markdown Reference for tips and a tutorial on making a code block.

You should be able to just return the string. h is a html helper.

  api.decorateWidget('poster-name:after', function(helper) {
    return 'a string';
  });

That works great! Thanks!

Can I mark an answer as “Solved” somehow? I saw it in discourse already, but the button that is described in the according plugin is not visible to me :frowning:

“Solved” button available only for Support category in meta.