Affichage des variables Discourse sur d'autres pages

Bonjour.
Je souhaite afficher certaines statistiques du site depuis la page /about sur la page d’accueil, en combinaison avec un autre plugin.

Par exemple, j’ai ajouté Membres : {{number model.stats.user_count}} au fichier .hbs d’un plugin, mais lors de la reconstruction de Discourse, il n’affiche que 0. J’ai pourtant plus de 0 utilisateurs. :slight_smile:

Des idées ou des pistes ?

It’s hard to say without knowing more about the plugin. It might be easier to get that data from a page that has it already.

1 « J'aime »

Basically, I’m writing a plugin to display board statistics on the bottom of the forum, similar to what vBulletin does.

So far, I have this:
SiteStats

In my plugin directory, my /assets/javascripts/discourse/components/site-stats.hbs is the following:

<div class="board-statistics-headrow">{{d-icon "far-chart-bar"}}  {{i18n 'about.stats'}}</div>
<div class="board-statistics-row">
  Threads: {{number model.stats.topic_count}}  Posts: {{number model.stats.post_count}}  Members: {{number model.stats.user_count}}>
</div>
</div>

I grabbed the {{number model.stats.topic_count}} from the about.hbs file inside the Discourse GitHub repository.

You have two ways to do this.

Just check which (Rails) controller is being called on the /about page to fetch the data you need.

In your ember route file’s model method, you can call that controller via ajax and fetch the required data.

Otherwise,

If you’ve written your own controller, then create a new method and copy the logic from the controller you found to your new controller and (maybe) filter the data you need if that’s required.

this model variable is what is returned by the model method of the route in question.

I think you should go through this guide to get a holistic understanding of how things work in discourse.

2 « J'aime »

Alright. I’ll check out that Plugin guide and see if I can make any additional progress.

So far, I have https://github.com/NCC-Gnisha/discourse-site-statistics

1 « J'aime »