繁体   English   中英

Prestashop 将 css 添加到模块

[英]Prestashop add css to a module

我正在 prestashop 1.4 中创建一个模块,比如blocktest

模块/blocktest/blocktest.php:

...

public function hookLeftColumn($params)
{
    global $smarty;
    $smarty->assign(array(
        'test' => 'test'
    ));
    return $this->display(__FILE__, 'blocktest.tpl');
}

public function hookHeader()
{
    Tools::addCSS($this->_path.'blocktest.css', 'all');
}

模块/blocktest/blocktest.css:

* { background-color: red; }


问题:

我的 css 不包括在内。


我尝试了什么:

admin > preferences > performances > smarty中,我已将缓存设置为no ,并强制编译为yes admin > preferences > performances > smarty中,缓存设置为no

现有模块使用相同的 css 包含: Tools::addCSS($this->_path.'blocktest.css', 'all'); ,但 css 文件位于<themeName>/css/modules/<moduleName>/<moduleName>.css中。 这很奇怪,因为 $this->_path 指向模块文件夹: modules/<moduleName>/

但无论如何,我试图将我的 css 文件放在<themeName>/css/modules/blocktest/blocktest.css中,但这不起作用。 也许我错过了什么

您还记得在模块安装期间为 header 注册一个挂钩吗?

function install() {
    if (!parent::install())
        return false;
    if (!$this->registerHook('header'))
        return false;
    return true;
}

没有它,您将不得不使用“管理”>“模块”>“职位”中的“移植模块”function 来执行此操作。 始终使用 Firebug 等工具检查您的文件是否存在。

另外,我认为缺少一些东西,您能否向我们提供您模块的完整代码? 请向我们提供您也使用的 Prestashop 版本。

其他解决方案:

$this->context->controller->addCSS(($this->_path).'style.css', 'all'); 
$this->context->controller->addJs(($this->_path).'script.js', 'all'); 

问候,

来源信息:

http://www.prestashop.com/forums/topic/235476-solucionadoerror-en-mi-1ra-web-warning-function-addcss-is-deprecated-in/

这很奇怪,因为 $this->_path 指向模块文件夹:modules//

是的,它是(奇怪的),但是......在 addCSS function 中,它被(模块)主题 css 文件夹覆盖

public static function addCSS($css_uri, $css_media_type = 'all')
{
  global $css_files;
   ...
  $css_uri = str_replace(__PS_BASE_URI__.'modules/', __PS_BASE_URI__.'themes/'._THEME_NAME_.'/css/modules/', $css_uri, $different);
   ...
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM