How to Add a View Counter in a Custom Discourse Theme?

I am using a custom Discourse theme and want to display the number of views for each topic. The default Discourse setup includes this feature, but it is not visible in my theme.

I checked the template files and found a section where column headers for sorting topics include an option for views. However, I can’t find where the actual number of views is being displayed in the theme.

How can I add the view count to my theme? Where should I insert the correct code to make it appear? Also, is there a way to do this without modifying the core files, only using theme components or available customization options?

IIRC post views is one of the arguments of a post. I did this a while back to fetch some other data, but I made a mental note that you can get the views the same way.

Using this.args will do this. Display it to see what are the arguments, and the views should be one of the arguments.

I know this is a kind of a non-answer, but I hope it points you in the right direction.


In the event this is not what you are talking about, is it okay to send a screenshot with what you are trying to achieve? By default, the topic list shows the views counter.

1 Like

this might help

3 Likes