The discussion revolves around creating a Handlebar helper function in a Discourse theme. Kumar_Karuppaiah seeks help with implementing a helper function that works across the application, sharing code and screenshots. pfaffman suggests consulting the Developer’s guide to Discourse Themes and references existing themes or plugins for examples. Johani clarifies that the helper should be called with arguments in .hbr files, such as {{sample "some string"}}, and explains that block helpers require # and proper closing tags. Kumar_Karuppaiah confirms the solution works, and pfaffman acknowledges the helpful response, noting it inspired code refactoring.
Your code should work, but you’re using your helper
{{sample}}
in the template without passing it any arguments. Even if you’re testing to see if things work, pass it a test string like
{{sample "some string"}}
You need to do that because you’re using the helper in a raw hbr template. For testing purposes, the helper should work even if you don’t pass it anything in regular hbs templates.
If you’re creating a block-helper, then it needs to have # and you need to close it like so.
{{#sample}}
{{/sample}}
Adding ~ to your helper optionally trims whitespace between any HTML tags it returns. So
Thank you for your reply. You are helping me a lot.
Yes, I have already gone through the documentation, existing themes and few examples, and created this sample project. But I am not sure about how to call the helper function in handlebar file. I tried it in multiple ways, and it was not working. That’s why, I posted here.