Receive the full description of a category in a theme

AFAIK, the description is stored (and maintained) in the first section of the first post in a description.

I want to add links near “top”, “Latest” buttons in the category. As a theme can not be configured for each category, I though I can simply add the data for the links in the “hidden part” of a category description - as only the first fragment of the category description is shown in the category list.

The data would look like this {TAG,linkText,linkTitle,linkHref}.

Sorry, I guess its not the best:

Is it possible to get the full data of the description text of a category in a theme / widget?

Thank you in advance.

Yes, that is what Discourse Category Banners does.

2 Likes

Well, I think

  • category.description returns the well formed category description
  • category.description_text returns the plain data

but both are just returning the first chapter of the description and not the complete first post of the category which contains the description. Do I miss something?

Oh that is the expected behavior. Discourse uses just the first paragraph of the about topic as the category description everywhere in the UI.

If you need anything else you will need to do an extra API call for the content.

2 Likes

would this be possible in a theme component? Do you have a example?

Discourse Category Sidebars does exactly this!

4 Likes

If the goal is to conditionally render the links on specific category pages, then I recommend taking a step back and trying a different approach.

Let’s say you have a setting like this

target_category, link_text, link_title, link_href

You can then do something like this.

api.addNavigationBarItem({
  displayName: text, // link text
  name: title, // link title
  href: href, // link href
  customFilter: category => {
    return (
      category && category.name.toLowerCase() === TARGET_CATEGORY.toLowerCase() // target category
    );
  }
});

The important bit here is the customFilter because I think that’s what you’re after.

If you have multiple links, you’ll need to wrap that in a forEach

5 Likes

Thank you @Falco. This was exactly what I need.

Thanks @Johani. I thought about your suggestion. Unfortunately, we have a huge amount of categories and the configuration in the settings would be large and not manageable. Therefore I wrote this theme.

I got it working right. After adding support for parent_categories and fixes some minor glitches, I will document it and “release it in a proper way”.

Finally, I guess this is it. Feel free to use it. A big “Thank you” to everyone who’s working on discourse. Awesome work.

Link to the theme component:

2 Likes