Display replies and views

How to display replies and views in the category section? With a label saying replies and views. Posted a screenshot with the placement

I don’t think anyone has built this yet but if you need it done quickly, try the marketplace.

1 Like

Are there any resources that can help me build it myself or someone that can guide me through it? I am not in a rush

You’ll probably get away with building a Theme Component.

Looks like the data is probably in the Serializer already:

https://github.com/discourse/discourse/blob/c68563a281b64e00affd8b56e1d06528697a6e4e/app/controllers/categories_controller.rb#L265

The serializer includes a TopicListSerializer:

https://github.com/discourse/discourse/blob/dc1836573d96768b4cc685c52c2c15aeac9f069e/app/serializers/category_and_topic_lists_serializer.rb

So the data should be passed down to the Ember model.

You need to look at the templates.

Digging down those you get to this:

https://github.com/discourse/discourse/blob/dc1836573d96768b4cc685c52c2c15aeac9f069e/app/assets/javascripts/discourse/templates/components/categories-and-latest-topics.hbs

Then further this:

https://github.com/discourse/discourse/blob/dc1836573d96768b4cc685c52c2c15aeac9f069e/app/assets/javascripts/discourse/templates/components/categories-topic-list.hbs

And down to this:

https://github.com/discourse/discourse/blob/dc1836573d96768b4cc685c52c2c15aeac9f069e/app/assets/javascripts/discourse/templates/components/latest-topic-list-item.hbs

This is probably the one you need to modify.

You might refer to this for some ideas:

https://github.com/discourse/discourse/blob/dc1836573d96768b4cc685c52c2c15aeac9f069e/app/assets/javascripts/discourse/templates/list/topic-list-item.hbr

This is not entirely straightforward for someone not used to this, but persevere and you’ll get it to work.

However, consider baby steps. Consider a more simple change first to get used to doing this.

1 Like

This chunk of code displays the views in the latest tab, not in the categories tab. Any easy way for it also work for the categories tab?

I suspect you only need to change a template or two, one for the header and another for each topic list item.

Have you tried adding this?:

<td class="num views {{topic.viewsHeat}}">{{number topic.views numberKey="views_long"}}</td>

Can’t promise that will work out of the box, but should get you working in the right direction.

Make sure you understand the basics of how Ember works. Maybe read this section of the Guides at a minimum: Templates are HTML - Components - Ember Guides