开发者

Prestashop add css to a module

开发者 https://www.devze.com 2023-03-27 16:08 出处:网络
I am creating a module in prestashop 1.4, say blocktest modules/blocktest/blocktest.php: ... public function hookLeftColumn($params)

I am creating a module in prestashop 1.4, say blocktest

modules/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');
}

modules/blocktest/blocktest.css:

* { background-color: red; }


Problem:

My css is not included.


What i tried:

In admin > preferences > performances > smarty, i have set cache to no, and force compile to yes. In admin > preferences > performances > smarty, cache is set to no.

Existing modules uses the same css inclusion : Tools::addCSS($this->_path.'blocktest.css', 'all');, but the css file is in <themeName>/css/modules/<moduleName>/<moduleName>.css. Which is wierd, because $this->_path points to the module 开发者_如何转开发folder : modules/<moduleName>/.

But anyway, I tried to put my css file in <themeName>/css/modules/blocktest/blocktest.css, that doesn't work. Maybe i am missing something


Did you remember about registering a hook for the header during module's installation?

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.


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/


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

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号