Alex Harchenko Alex Harchenko - 18 days ago 9
PHP Question

How to create a separate template to output the category in Opencart 2?

There are several categories of goods in the store on OpenCart 2 and need for one another structure and design. How it can be implemented? Visited options with the creation of the controller and the template output, but does not work...

Answer

Solved. Can someone come in handy.

In the file \catalog\controller\product\category.php

Replace code:

if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/product/category.tpl')) {
            $this->response->setOutput($this->load->view($this->config->get('config_template') . '/template/product/category.tpl', $data));
        } else {
            $this->response->setOutput($this->load->view('default/template/product/category.tpl', $data));
        }

To this:

$template = 'category.tpl';
        if ($category_id == 72) { $template = 'category-72.tpl'; }

        if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/product/'.$template)) {
            $this->response->setOutput($this->load->view($this->config->get('config_template') . '/template/product/'.$template, $data));
        } else {
            $this->response->setOutput($this->load->view('default/template/product/'.$template, $data));
        }

Instead of the 72 put your category id.

Creating a template our category here :

\catalog\view\theme\NAME_THEME\template\product\category-72.tpl

Then go to Admin -> Modules -> Modifiers and update the cache. Done.