3

我正在 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,但这不起作用。也许我错过了什么

4

3 回答 3

5

你还记得在模块安装过程中为 header 注册一个钩子吗?

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

Without it you will have to use "transplant module" function from Admin > Modules > Positions, to do this. Always check with tools like Firebug to verify whether your files are there.

Also, I think there is something missing, can you supply us with the full code of your module? Please, provide us with a Prestashop version that you use as well.

于 2011-08-11T22:30:35.230 回答
3

Other solution:

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

Greetings,

source info:

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

于 2013-10-04T11:16:26.797 回答
1

Which is wierd, because $this->_path points to the module folder : modules//

yes it is (weird), but... in the addCSS function, it is overriden with (module) themes css folder

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);
   ...
}
于 2012-02-19T11:42:03.693 回答