# Theme-Component v Plugin: What's the difference

**URL:** https://meta.discourse.org/t/theme-component-v-plugin-whats-the-difference/153951
**Category:** Development
**Created:** [June 5, 2020, 2:56pm UTC](https://meta.discourse.org/t/theme-component-v-plugin-whats-the-difference/153951 "2020-06-05T14:56:51Z")
**Posts on this page:** 3
**Page:** 2

<div class="post-metadata">

### Author: ![JQ331](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@JQ331](https://meta.discourse.org/u/JQ331)
#### Post date: [June 9, 2020, 9:18pm UTC](https://meta.discourse.org/t/theme-component-v-plugin-whats-the-difference/153951/22 "2020-06-09T21:18:11Z")

</div>

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)?

---

<div class="post-metadata">

### Author: ![tshenry](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/tshenry/32/119495_2.png) [@tshenry](https://meta.discourse.org/u/tshenry)
#### Post date: [June 9, 2020, 9:40pm UTC](https://meta.discourse.org/t/theme-component-v-plugin-whats-the-difference/153951/23 "2020-06-09T21:40:08Z")

</div>

> [@JQ331](#):
>
> Not sure why the group owner code didn’t work for me–probably something to do with how I set up the plugin.

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

> [@JQ331](#):
>
> 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 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/common/head\_tag.html at ddf3d7e003423e2e5f83446a80cab78d51f09e2d · awesomerobot/discourse-featured-topics · GitHub](https://github.com/awesomerobot/discourse-featured-topics/blob/ddf3d7e003423e2e5f83446a80cab78d51f09e2d/common/head_tag.html#L12)

2. There is no built-in concept of custom group field like there is with [custom user fields](https://meta.discourse.org/t/how-to-create-and-configure-custom-user-fields/113192). I believe you would need to build a plugin that adds all the necessary bits and pieces for that to work.

---

<div class="post-metadata">

### Author: ![JQ331](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@JQ331](https://meta.discourse.org/u/JQ331)
#### Post date: [June 9, 2020, 9:51pm UTC](https://meta.discourse.org/t/theme-component-v-plugin-whats-the-difference/153951/24 "2020-06-09T21:51:14Z")

</div>

> [@tshenry](#):
>
> I don’t _think_ that gives you access to the owner data, but maybe I am missing something.

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.

> [@tshenry](#):
>
> The theme component I linked to does something similar to make sure the ajax call only happens on `/latest` or the homepage

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

> [@tshenry](#):
>
> Also if you haven’t already, definitely take a look at [Developer’s guide to Discourse Themes](https://meta.discourse.org/t/developer-s-guide-to-discourse-themes/93648)

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.

[Previous page](https://meta.discourse.org/t/theme-component-v-plugin-whats-the-difference/153951.md?page=1)
