Show category description on CMS page

Is it possible in Prestashop 1.7 in the CMS pages to display the category description on the category page? Somehow I can't find any info anywhere. Well I have some CMS pages and would like te show there description of category with products. For example i have category page "dresses" - this category has a description, but I can find a way of displaying it.

PrestaShop expert answer


This case requires custom development. It is necessary to alter prestashop core and this is the only one available method.
controllers/front/CmsController.php has this code:

'cms' => $this->cms,

replace it with:

'cms' => $this->replaceShortcode($this->cms),

and create function:

    public function replaceShortcode($contents){
        preg_match_all('/\[catdesc\:[(0-9)]+\]/i', $contents->content, $matches);
        foreach ($matches[0] as $index => $match)
            $explode = explode(":", $match);
            $category = new Category($explode[1], $this->context->language->id);
            $contents->content = str_replace($match, $category->description, $contents->content);
        return $contents;

then, in your cms pages contents you will be able to use shortcode [catdesc:5]  - shortcode will display description of category with ID 5 (you can replace 5 with any other ID).

author milos myszczuk
Answer by Milosz Myszczuk PrestaShop expert, official PrestaShop community moderator. PHP developer, specialist in relative and spatial databases management, GIS Analyst, CEO & founder of VEKIA interactive agency. Read more about VEKIA company
If you like my articles and want much more valuable tips, feel free to send me donation