Tags at the top of the topic list in a Category

You can get the top_tags easily :

Import ajax – import { ajax } from "discourse/lib/ajax"; , then →

ajax(`/c/general.json`).then((data) => {
  console.log(data.topic_list.top_tags);
});

This is the general category; you can replace this with a variable or theme-component setting.

If you want to display all tags unfiltered by category, /tags.json .

To use the outlet above the topic list, the outlet name is /javascripts/discourse/connectors/above-main-container/{name-of-your-file}.hbs . I would recommend seeing how this is done in other theme-components and reading Using Plugin Outlet Connectors from a Theme or Plugin.


More difficult is getting all tags. You can look at the data structure from /c/general.json, which looks like this. Instead of doing data.topic_list.top_tags, you could iterate each in data.topic_list.topics and add each tags for each topic to an array. data.topic_list.topics.map((topic) => topic.tags);.

Hope this helps! :slight_smile:

2 Likes