Hoe registreer ik een ember helper voor een thema component?

AI-generated summary

A user asks how to register an Ember helper for a theme component, specifically to compare a category slug with a string in a template. They note that vanilla Ember logic doesn’t allow direct comparisons like {{#if category.slug == 'foobar'}}. They propose two solutions: adding a method/property to the category object or registering an eq helper, referencing ember-truth-helpers as a standard. However, they’re unsure how to implement this in a theme, as existing guides are for plugins. They also suggest the core team consider adding common logic helpers to discourse-commons for easier theme development. user1

I’m writing some theme component that would do something arbitrary to a specific category. The only variable I have access in the component is the list of categories, and I’d like to extract the correct one.

c for c in category_list if c.slug == 'foobar'

With ember limited logic, I would need to do something like that:

{{#if category.slug == 'foobar'}}

which is not possible with vanilla version. We need to add a helper for something as low level as a comparison.

There are two main options:

  1. Add a method/property in the object that would return True only for the correct category in the list.
  2. Register an eq helper, and is appears to me that this one is quite the standard.
    {{#if (eq person "John")}} hello {{/if}}

So far, I don’t know how to do any of that for a theme component.
I’ve seen a post explaining how to do 2. it in a plugin but it seems irrelevant for a theme.

Can someone explain to me how to proceed?

And can the core team consider adding quite-standard logic helpers in discourse-commons? I’m sure the would be useful for a lot of low skill theme dev like me.

1 like