Is it possible to add content to an category page?

Hello,

I am building a portfolio website for a studio. I have multiple categories (8). For example:

/projects/interior
/projects/design
/projects/garden

etc.

I have one category template. Is it possible to add specific content to a specific category? For example some content about design on the design category page?

My approach is: make for every category a unique template. But this seems a little bit overkill since only content is different from every category.

Thanks

Yes, of course you can do that on a single template. These categories are normal pages, right?

Thanks for your reaction.
I guess not ‘normal’ pages. I show all projects with that specific category on that page. Lets call it an category overview page.

That makes it still a normal page, and if that category page has some information about the category, then you might just as well display it in the same way you show page specific information on any other page.

Sorry for the confusing. Maybe I describe it wrong.

I filter the category pages with a route ( https://getkirby.com/docs/cookbook/content/filter-via-route )
So it is not a ‘normal’ page I guess.

Thanks

Well, you structure above looked as if those categories were pages.

Anyway, where do you store the information about the categories then? The template you use for the categories is the projects template then?

Sorry for the confusing.

I have a projects controller and template as well (same name).

?

I have 8 choosable categories in my project blueprint.
Then I have a project overview page with all published projects and a filter by tags/categories via a route to filter those projects by category.

That’s not really what I meant. I wanted to know where you (intend to) store the description of each category that you then want to show on the page when filtering by category.

But let’s assume you store that information in a structure field categorieswith two fields name and description in the projects page.

You probably use code similar to the one from this recipe: https://getkirby.com/docs/cookbook/content/filter-via-route, only maybe using category instead of tag.

Then you can fetch the information from the structure field and pass it to the template

<?php

return function ($page, $category) {

    $projects = $page->children()->listed();


    if ($category) {
        $projects = $projects->filterBy('category', $category, ',');
        $categoryItem = $page->categories()->toStructure()->findby('name', $category);
    }

    return [
        'articles' => $articles,
        'categoryItem' => $categoryItem ?? null
    ];

};

In your template, you can then render this

if ($categoryItem) {
  echo $categoryItem->description();
}
1 Like

Thanks for you help and sorry for my late reply. I am looking into it now. I will let you know if I can get it working. Thanks!