So I see and get that I have to create these functions myself, it’s not like Jinja2 with useful builtin things to do this.
But where do I create these handlebars functions in my plugin? I see quite some examples in here: Repository search results · GitHub
But I don’t really see a pattern in this folder structure. I’ve created my own function in discourse-group-custom-fields/assets/javascripts/discourse/app/helpers/contains.js, but when I try to use it in discourse-group-custom-fields/assets/javascripts/discourse/connectors/group-edit/field-container.hbs I get the error Uncaught Error: Attempted to resolve "contains", which was expected to be a component, but nothing was found.. So obviously, this is not a path where Discourse is looking, or I’m doing something wrong.
import RawHandlebars from "discourse-common/lib/raw-handlebars";
import { htmlSafe } from "@ember/template";
import { rawConnectorsFor } from "discourse/lib/plugin-connectors";
//RawHandlebars.registerHelper("contains", function (args) {
// const connectors = rawConnectorsFor(args.hash.name);
// if (connectors.length) {
// const output = connectors.map((c) => c.template({ context: this }));
// return htmlSafe(output.join(""));
// }
//});
Handlebars.registerHelper('contains', function(needle, haystack, options) {
needle = Handlebars.escapeExpression(needle);
haystack = Handlebars.escapeExpression(haystack);
return (haystack.indexOf(needle) > -1) ? options.fn(this) : options.inverse(this);
});
The topic below suggests that it could be in the initializers directory and have the es6 extension.
So I moved my contains.js to that directory and added .e6 as the extension and I got the same error. Some help or docs would be great ![]()