基于OpenCart中的路由向页面添加CSS样式表 [英] Adding CSS stylesheet to pages based on route in OpenCart

查看:832
本文介绍了基于OpenCart中的路由向页面添加CSS样式表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用opencart(版本1.5.1.3.1)作为客户端存储,我想知道什么是最好的方式来编码,所以我可以为某些路由添加某些样式表。

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.

例如,在我的类别页面上,我想有一个不同的样式表为默认样式表,或者一个将超过我的自定义工作表的默认样式。我明显地使用这个多个路由,并希望这样做尽可能少的编辑,以减少框架中的编辑量,我需要在任何阶段升级(和opencart的知名随机更改和错误修复版本很可能)

For example, on my category page I'd like to have a different stylesheet to the default one, or one that will over ride the default styles with my custom sheet. I have use for this for more than one route obviously, and want to do this with as little edits required as possible, so as to reduce the amount of edits in the framework should I need to upgrade at any stage (and with opencart's well known random changes and bug fix releases this is quite probable)

推荐答案

打开 catalog / controller / common / header .php

紧跟在后面的protected function index(){ line put

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);
    }

然后转到您当前的主题,并在 catalog / view / your-theme / stylesheet / 文件夹 product_category.css 除了将正斜杠替换为下划线,然后将 .css ,即 common / home common_home.css

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

这篇关于基于OpenCart中的路由向页面添加CSS样式表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆