Theme-Component v Plugin: What's the difference

Thanks, @tshenry. Not sure why the group owner code didn’t work for me–probably something to do with how I set up the plugin.

I have found the AJAX approach to work as an “MVP” method. BTW, I believe you can make an API call to [forum-url]/groups.json to get back all site groups, and then you can loop through from there, so no need to make multiple calls.

I was hoping to ask:

–For the AJAX/JSON API approach, do you know how to make it so that a function only runs when a user goes to a specific page? Right now, If I put the AJAX code in the </ head> section of my customize dashboard, I can get it to work, but it runs every time the site is loaded (when I only want it to run when the group index page is loaded)

–In my case, I’m using AJAX right now especially because I not only need to show group owners, but also a few other new traits of a group that I am adding. These would be like custom fields of the group that I am trying to retrieve and show. Right now, the “MVP” version (while I’m still learning how the discourse codebase works) is to save them to a separate non-discourse database that I pull from and add to the group index page.

Obviously, the cleaner solution would be to add the custom traits to the groups in the discourse database and call those back. Just trying to gauge the type of operation that would be required here. Would that require redoing a bunch of the discourse files (controllers, models, templates)?

1 Like

I can put it in a little GitHub repo when I get a chance.

I don’t think that gives you access to the owner data, but maybe I am missing something.

Regarding your questions:

  1. The theme component I linked to does something similar to make sure the ajax call only happens on /latest or the homepage. I would try to build off of that idea: discourse-featured-topics/head_tag.html at ddf3d7e003423e2e5f83446a80cab78d51f09e2d · awesomerobot/discourse-featured-topics · GitHub

    Also if you haven’t already, definitely take a look at Developer’s guide to Discourse Themes

  2. There is no built-in concept of custom group field like there is with custom user fields. I believe you would need to build a plugin that adds all the necessary bits and pieces for that to work.

2 Likes

You’re right. I was forgetting–that is something I also store in a separate database that I call with AJAX (and some other magic) right now.

Great idea–I see what you did with if ((url == "/") || (url == "/latest") ) in that repo. I can do something similar.

Yes–I’ve gone through that guide as well as the other ones I’ve been able to find. It’s a great guide, but I have found the transition from that guide (and other ones on meta) to implementing this kind of customization to be tricky. These customizations require, as far as I can tell, really understanding how the templates, controllers, and models fit together in the Discourse codebase.

Digression

Ember may be a great system for building performant apps, but I do find it difficult to tease out how the different files are related. For example, finding the right template in a view in the Github repo does not tell you much about what other templates that one links to, and then especially which controllers and other models may be relevant. It’s possible, but slow going, and you really need to understand those relationships to do these customizations.

In Angular, as an alternative method, the pieces of the view components are normally grouped together with an html, typescript, and css file, and then other relevant files are clearly marked in these files (so services that are in use are identified in the typescript file and other components that are inserted are clearly marked in the html file). As far as I can see that’s not how the Discourse ember structure works (not to knock that structure–its a very stable, highly performant app–it just takes getting used to).

Hence my using stuff like AJAX to get at the same result while I continue to try to understand how the discourse pieces fit together.

2 Likes