Getting categories on your website via JS

Hey all! This is not a question post, just wanted to contribute something I had been searching for quite frequently, but figured out myself.

Basically, if you want to get any website-related data on the client side, you can get it from the container object.

For eg, the code to get categories is

const container = Discourse.__container__;
const categories = container.lookup("controller:navigation/categories").site.categories;

These features aren’t documented anywhere, but you can figure it out via trial and error.

If you want to do anything more complex, you can also have a look at this post: How to reverse engineer the Discourse API

5 Likes