在 prestashop 中将我的 css 添加到主题 [英] add my css to theme in prestashop

查看:59
本文介绍了在 prestashop 中将我的 css 添加到主题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是 prestashop 的新手.我创建了我的 css 文件并想将它添加到 prestashop 主题.如何添加新填充并使 prestashop 读取标题部分中的文件?在论坛中,我看到他们说要将其添加到 hookheader,我尝试将其添加到某个模块并执行以下操作:

I'm new in prestashop. I created my css file and want to add it to prestashop theme. How can i add the new fill and make prestashop read the file in the header section? In forums i see that they said to add it to hookheader , i tried to add it to some module and do the following:

1) 添加到主题头文件 {hook h="myCssHook"}

1) add to the theme header file {hook h="myCssHook"}

2) 添加一些 rendom 模块功能:

2) add to some rendom module function:

public function myCsshook(&params)
{
$this->context->controller->addCSS(($this->_path).'prestashop/myshop/theme/css/myoverride/myCsstheme.css', 'all');
}

3) 在模块安装中复制并添加:

3) in the module installition copy and add:

|| $this->registerHook('myCssHook') == false

它没有用.我正在使用 prestashop 1.6.1.1

and it didn't work. I'm using prestashop 1.6.1.1

推荐答案

最好的方法是在正确的控制器文件的 setMedia() 函数中添加以下内容.

The best way to do that is to add the following in the setMedia() function of the correct controller file.

$this->addCSS(_THEME_CSS_DIR_.'myoverride/myCsstheme.css');

例如,如果你想把你的css添加到你所有的产品页面,你必须在controllers/front/ProductController.php之后添加这段代码

For example, if you want to add your css to all your Products pages, you will have to add this code in controllers/front/ProductController.php after

$this->addCSS(_THEME_CSS_DIR_.'product.css');

如果你想把它添加到你的所有页面,你必须在classes/controller/FrontController.php之后添加这段代码

If you want to add it to all your pages, you will have to add this code in classes/controller/FrontController.php after

$this->addCSS(_THEME_CSS_DIR_.'global.css', 'all');

一个更好(更干净)的方法是创建一个覆盖文件.
例如,对于 FrontController,在 override/classes/controller/FrontController.php 中创建一个名为 FrontController.php 的新文件并放置以下代码:

An even better (and cleaner) way to do that is to create an override file.
For example, for FrontController, create a new file named FrontController.php in override/classes/controller/FrontController.php and put this code:

<?php
class FrontControllerCore extends Controller
{
    public function setMedia()
    {
        parent::setMedia(); // This will take all code in setMedia() of the original classes/controller/FrontController.php
        $this->addCSS(_THEME_CSS_DIR_.'myoverride/myCsstheme.css');
    }
}

您可以为每个控制器创建一个覆盖文件.如你所愿.

You can create an override file for each of your controllers. As you wish.

这篇关于在 prestashop 中将我的 css 添加到主题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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