Adding CSS stylesheet to pages based on route in OpenCart

前端 未结 1 1187
眼角桃花
眼角桃花 2020-12-31 21:02

I\'m using opencart (version 1.5.1.3.1) for a client store, and am wondering what the best way to code it so I can have certain stylesheets added for certain routes.

相关标签:
1条回答
  • 2020-12-31 22:01

    Open catalog/controller/common/header.php

    Right 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 your current theme, and create a file in catalog/view/your-theme/stylesheet/ folder called product_category.css and put your styles in that. The stylesheets work off your route name except you replace the forward slash to an underscore followed by .css, ie common/home becomes common_home.css

    Note that is is going to use the override method rather than replacing your default stylesheet

    0 讨论(0)
提交回复
热议问题