Adding CSS stylesheets to pages along a route in OpenCart

I use opencart (version 1.5.1.3.1) for the client repository, and I wonder how best to encode it so that I can add specific styles for specific routes.

For example, on my category page, I would like to have another default stylesheet, or one that will navigate the default styles with my custom sheet. I use this for more than one route, obviously, and I want to do it with the minimum changes that are necessary, as far as possible, in order to reduce the number of corrections within the framework, if I need to update at any stage (and using random familiar with opencart and bug fixes, this is pretty likely)

+6
source share
1 answer

Open catalog/controller/common/header.php

Immediately after the line protected function index() { on a new line, put

  $route = empty($this->request->get['route']) ? 'common/home' : $this->request->get['route']; $css_file = str_replace('/', '_', $route) . '.css'; if(file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/stylesheet/' . $css_file)) { $this->document->addStyle('catalog/view/theme/' . $this->config->get('config_template'). '/stylesheet/' . $css_file); } 

Then go to the current theme and create a file in the catalog/view/your-theme/stylesheet/ folder called product_category.css and put your styles in it. Style sheets work with your route name, except that you replace the slash with an underscore and then .css , i.e. common/home becomes common_home.css

Note that this will use the override method instead of replacing your default stylesheet

+11
source

Source: https://habr.com/ru/post/902488/


All Articles