Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Prestashop add css to a module

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

like image 620
Benjamin Crouzier Avatar asked Nov 23 '25 05:11

Benjamin Crouzier


1 Answers

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.

like image 188
Matthew Morek Avatar answered Nov 24 '25 20:11

Matthew Morek