When to use a plugin vs theme component?

I need to do little changes to some views:
Eg:

  • change the datetime format to extended one (DD/MM/YYY HH:MM)
    Screenshot 2024-02-28 at 12.14.36

  • add a tooltip to long category titles
    Screenshot 2024-02-28 at 12.21.37

  • view long category titles on two rows
    Screenshot 2024-02-28 at 12.21.56

Do I need to create a plugin for every change? even if is really small like only css?
Thanks for your help.

1 Like

No, plugins are only required if you intend to change the back-end.

If it’s just a local change you can go to Admin → Customize → Theme and enter changes into a new Theme Component, then add it to your current Theme.

Take a look at theme developers - Discourse Meta, especially:

8 Likes

thanks!
So if I need to change a label or add a tooltip I need to create a theme but if I need to add a new column to a page (eg: the topic list) I need to create a plugin?

The distinction is this:

  • If you need to change the API, e.g. any data in .json route, changes to authorisation, back-end processing of data, you need a plugin
  • For many front end changes that don’t need different data, you only need a TC. ie a lot of presentational changes, or any logic in javascript that is not sensitive.
5 Likes

And a gray area (which doesn’t apply here, I think) is if you need data that is not available (like user custom fields) you could either use AJAX to pull that data with javascript when you need it, or have a plugin that adds the data to the serializer.

5 Likes

ok thanks. In the guide I don’t undestand how can I setuo and import a TC locally, there’s only an example for a remote one.

I would suggest using this wonderful tool, to create TC easily locally:

2 Likes

Unless you have a very small CSS change, I’d recommend using a remote theme or the CLI tool.

But if you click the “install theme” dialog will allow you to create a theme (or theme component if you do it on the component page)

inside the category topics list I need to add a new column with the “created_at” column and change the date from “tiny” to extended (eg: DD/MM/YYYY HH:MM)

If you want to add new stuff to a template, I would start with GitHub - discourse/discourse-theme-skeleton: Template for Discourse themes, but I don’t know how to go about adding a column there. I guess there’s some javascript magic you could do, but that’s not my wheelhouse.

You know that you can see that information if you mouse-over, right?

image

Also see Plugin outlet locations theme component, but there’s no plugin outlet there.

2 Likes

You have these plugin outlets: topic-list-after-columns and topic-list-header-after.

Good catch. It seemed wrong that there was no outlet there. I guess the theme component just doesn’t show it.

1 Like

The plugin outlet locations theme component does not show raw outlets at the moment.

This theme component shows you how to add a column GitHub - discourse/discourse-add-category-column

3 Likes