I’ve created a custom plugin to include some extra fields for groups. But they only apply to groups with the name “chapter” in it. So it doesn’t make sense to have them in groups for other purposes. Is there some way I can create a condition that checks e.g. if chapter in group.name; then chapter = true?
I have the following:
I want to hide the control group at the top if the group name does not have the word chapter in it. I seem to already use some Jinja2 stuff from the example I used. If that’s anything like other Jinja2, then I can certainly create such a condition there. But then I need to know a few things.
If Jinja2 is fully available, how can I access the group name variable to create the condition?
If Jinja2 is not (fully) available, how can I create this condition then? Probably some other JavaScript should set a boolean I suppose. But the structure of these group variables and JavaScript logic is not known to me, any examples would great!
Oh wait… I now suddenly see some methods to test. If Jinja2 works here, then indeed in g.json the group name is visible and can be used for a condition…
An no, that doesn’t work. And it’s not Jinja2, it’s Handlebars specific stuff (but I suppose contains is not a native function?).
But that doesn’t work, I get a bunch of errors. I probably don’t use the right variable lookup. Although replacing group.name with simply "chapter_netherlands" also fails.
Error occurred:
- While rendering:
-top-level
application
discourse-root
group
group.manage
group.manage.profile
groups-form-profile-fields
plugin-outlet
plugin-connector
Uncaught Error: Attempted to resolve `contains`, which was expected to be a component, but nothing was found.
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: Search · handlebars · 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.