How to change category names via theme-component

AI-generated summary

Changing Category Names via Theme-Component

thoka is seeking advice on how to change category titles in different areas of the interface. They want to add linebreaks or omit the first part of the title, and also change the display of long names in the “link bar” to use a short name or ellipsis at the beginning.

Rhababo suggests using a plugin component to inject extra HTML into the category titles. They provide resources for getting started with theme development and modifying plugin outlets. For changing the names on the sidebar, Rhababo points to the relevant code and suggests overriding a function to achieve the desired result, but notes that this would require modifying core JavaScript and may cause difficulties with future Discourse updates.

I’m seeking for advice, how to change category titles in different areas of the interface.

Background: We are using quite long category titles for our school community, to give users enough background to know, which audience the category targets. We also repeat the name of the top category in the name of the subcategory.

I would like to be able to change the titles to include linebreaks

or be able to just omit the first part.

Another place is the “link bar”, where long names are abbreviated with dots at the end.
I would like to implement either an option for a short name or to use the ellipsis at the beginning:

For the first part, since you’re adding things to the existing category titles there are a few places that you could inject extra html via plugin component:

You can use this theme component to get an idea of where you can input things to your site:

This section goes into more detail on how you can add items to plugin outlets:

As for changing the names on the sidebar…here’s the code that controls that:

Overriding this function to something like

get text(){
    return "..."+this.category.name.substr(-10)

could work for you, but that requires modifying core javascript, outside of a template. A small change like this is probably harmless long term, but you may run into difficulties when discourse updates.

If someone with more insight than myself wants to chime in I’d listen to them.