Getting Topic Information

Newbie question: In your Developer’s Guide (Developer’s guide to Discourse Themes), you explain how to to get information about a user by using api.getCurrentUser();
and then console.log(user). Simple enough. However, how do you get similar information about a Topic when you are on a topic page? We’ve tried getTopic(), but no such method exists. How do get the values that are available to a Topic on a specific topic page and then use console.log to see what’s available to use?

There’s a number of ways to do that, but rather than shooting in the dark and suggesting ways that might not be relevant, I want to clarify first.

What are you trying to do? and how?

3 Likes

So what we were trying to accomplish is that we have certain HTML messages that we want to show sitewide, but instead of entering them individually on every topic, we wanted to just show them automatically depending on a topic tag. What we decided to do is to simply store the messages and tags in the setting and used a widget to target the tags on the individual topics based on the discourse container. Is the correct way to go about this? So something like this:

 const container = Discourse.__container__;
 const topicController = container.lookup("controller:topic");
 tags = topicController.get("target.currentRoute.parent.attributes.tags");

Then just compare the tags on the topic to those stored in the settings and display HTML or not based on the comparsion