تجاوز قائمة الفئات

Currently working out of an initializer for my custom plugin - I want to be able to add an arbitrary class (locked-category) for each locked category, but can’t quite figure out how.

I’m aware that I can edit the template for topic-list-item, however the class is conditional, dependent on whether the topic is locked or not.

Here’s the code in question:
TopicStatus.reopen({ statuses(){ if (this.topic.is_locked_down) { // I'd like to add the class to topic's classList } ... })

If anyone has ideas, anything is appreciated!

إعجاب واحد (1)

If

in your post refers to categories with limited read permissions then something like this will work if you add it to your initializer.

api.modifyClass("component:topic-list-item", {
  didInsertElement() {
    this._super(...arguments); // ensures core code runs first

    const privateCategory = this.topic.category.read_restricted;
    if (privateCategory) {
      // adds the class to topic list items that meet the conditional above 
      this.element.classList.add("locked-category");
    }
  }
});
3 إعجابات

Awesome, got it working, much appreciated!

إعجابَين (2)