如果组名包含特定名称,则隐藏某些组设置

我明白了,我需要自己创建这些函数,不像 Jinja2 那样有有用的内置函数来完成此操作。

但是,我在我的插件中在哪里创建这些 Handlebars 函数呢?我在这里看到了很多示例:Repository search results · GitHub

但我并没有真正看懂这个文件夹结构。我在 discourse-group-custom-fields/assets/javascripts/discourse/app/helpers/contains.js 中创建了自己的函数,但当我尝试在 discourse-group-custom-fields/assets/javascripts/discourse/connectors/group-edit/field-container.hbs 中使用它时,我收到了错误 Uncaught Error: Attempted to resolve "contains", which was expected to be a component, but nothing was found.。所以很明显,这不是 Discourse 正在查找的路径,或者我做错了什么。

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);
});

下面的主题表明它可能在 initializers 目录中,并且具有 es6 扩展名。

所以我把我的 contains.js 移到了那个目录,并添加了 .e6 作为扩展名,但我收到了同样的错误。一些帮助或文档将非常有帮助 :slight_smile: