• Dev
  • how to check if tag=tagname

I'm trying to use an extension only if i'm in a certain tag, so i need an if statement that check if i'm in that tag, how can i do this?

i need to make the tag name as variable, so user can set the tag from extension settings (or leave it blank to use extension in all tags)

    Justoverclock

    this.discussion.tags().find(tag => tag.overclocked() === true);

      Justoverclock

      const allowedTagId = 1;
      
      if (this.attrs.discussion.tags().some(tag => tag.id() === allowedTagId)) {
        // in allowed tag
      }

      discussion is passed as an attr to the DiscussionHero component, as seen here: https://github.com/flarum/core/blob/450ab61620dc2f79ebedbae1da5c0ad22bd81fdd/js/src/forum/components/DiscussionHero.js#L30

        davwheat

        thanks, so with this.attrs.discussion.tags() i get the current tag id, but how admin can know what is the tag id? (i want to make an admin settings to set the tag where this extension can work).

          Justoverclock

          You can get all the tags on the front-end with app.store.all('tags'), then populate an admin page using that data. You could, for example, create a drop-down box with every tag in it, so the admin can pick a specific tag.