bluecafe Posted September 21, 2011 Share Posted September 21, 2011 Hi experts, if I have installed a module that doesn't have a css folder within the theme folder and I want to make some css changes but don't want to apply the changes to the module file directly ... how can I make a module looking in the themefolder for a css file (as the standard prestashop modules do?). Hope somebody can give me a tipp. Thanks in advance. Link to comment Share on other sites More sharing options...
jhnstcks Posted September 21, 2011 Share Posted September 21, 2011 Try adding public function hookHeader() { Tools::addCSS(($this->_path).'yourcategoryname.css', 'all'); } to the php file of your module. Link to comment Share on other sites More sharing options...
bluecafe Posted September 21, 2011 Author Share Posted September 21, 2011 Thank you! I will go ahead an try this out. Link to comment Share on other sites More sharing options...
babu_babu Posted September 28, 2011 Share Posted September 28, 2011 Any success? Link to comment Share on other sites More sharing options...
bluecafe Posted October 2, 2011 Author Share Posted October 2, 2011 Not yet ... I tried with the nivo slider module and looked for the hook function function hookHome($params) { global $cookie; /* Languages preliminaries */ $defaultLanguage = intval(Configuration::get('PS_LANG_DEFAULT')); $languages = Language::getLanguages(); $iso = Language::getIsoById($defaultLanguage); $isoUser = Language::getIsoById(intval($cookie->id_lang)); if (file_exists(dirname(__FILE__).'/'.$isoUser.'links.xml')) if ($xml = simplexml_load_file(dirname(__FILE__).'/'.$isoUser.'links.xml')) { global $cookie, $smarty; $smarty->assign(array( 'xml' => $xml, 'this_path' => $this->_path )); return $this->display(__FILE__, 'slideric.tpl'); } return false; } Here I added Tools::addCSS(($this->_path).'slideric.css', 'all'); so that the function reads function hookHome($params) { Tools::addCSS(($this->_path).'slideric.css', 'all'); global $cookie; /* Languages preliminaries */ $defaultLanguage = intval(Configuration::get('PS_LANG_DEFAULT')); $languages = Language::getLanguages(); $iso = Language::getIsoById($defaultLanguage); $isoUser = Language::getIsoById(intval($cookie->id_lang)); if (file_exists(dirname(__FILE__).'/'.$isoUser.'links.xml')) if ($xml = simplexml_load_file(dirname(__FILE__).'/'.$isoUser.'links.xml')) { global $cookie, $smarty; $smarty->assign(array( 'xml' => $xml, 'this_path' => $this->_path )); return $this->display(__FILE__, 'slideric.tpl'); } return false; } But no css was added. Will have to dig into this deeper ... Link to comment Share on other sites More sharing options...
jhnstcks Posted October 2, 2011 Share Posted October 2, 2011 Sorry my mistake missed some code out. It should have its own hook not added to another hook. public function hookHeader() { Tools::addCSS(($this->_path).'yourmodulename.css', 'all'); } I presume you have also added the css file to the relevant folder, that being root/themes/css/modules/yourmodule/your odulename.css Edit: Adding the css to the global.css file will have the same results 1 Link to comment Share on other sites More sharing options...
bluecafe Posted October 2, 2011 Author Share Posted October 2, 2011 Thank you John, this looks logical that hookHeader is the css hook. Unfortunately it doesn't seem to work. I added public function hookHeader() { Tools::addCSS(($this->_path).'slideric.css', 'all'); } I placed a css file in the themes css/modules/slideric/ folder, cleared the cache, reinstalled the module but unfortunately the additional css won't be loaded (and there is no reference link in the source code). If I click on modules => position the module isn't listed in "header of pages" hook position either. The other modules loading an additional css file via hookHeader are listed in the "Header of pages" position. There must be something I am doing wrong, if I only knew what ... Link to comment Share on other sites More sharing options...
jhnstcks Posted October 2, 2011 Share Posted October 2, 2011 You will need to uninstall and then install the module again for it to activate the hook. Link to comment Share on other sites More sharing options...
bluecafe Posted October 2, 2011 Author Share Posted October 2, 2011 Yes I did this, I even deleted the module and reuploaded it. There must be something else I am missing ... I will try with another module to see if the problem is module related. Thanks for your support. Link to comment Share on other sites More sharing options...
bluecafe Posted October 2, 2011 Author Share Posted October 2, 2011 Ha ... got it !!! I had to add OR !$this->registerHook('header') to the install function. This was the original install function which didn't mention headerHook function install() { if (!parent::install() OR !$this->registerHook('Home')) return false; return true; } I added OR !$this->registerHook('header') so that it reads function install() { if (!parent::install() OR !$this->registerHook('header') OR !$this->registerHook('Home')) return false; return true; } Now it works! Thanks again, John, for pointing me to the right direction! 1 Link to comment Share on other sites More sharing options...
jerri69 Posted November 3, 2011 Share Posted November 3, 2011 Hi I tried to apply this to the blocktopmenu module and it almost works... after reinstall my page loads first themes/mytheme/css/blocktopmenu/mycss.css and then the original css file which replaces my css file and covers my changes. do You know how to replace an order of applying css files?. Link to comment Share on other sites More sharing options...
jhnstcks Posted November 3, 2011 Share Posted November 3, 2011 Hi I tried to apply this to the blocktopmenu module and it almost works... after reinstall my page loads first themes/mytheme/css/blocktopmenu/mycss.css and then the original css file which replaces my css file and covers my changes. do You know how to replace an order of applying css files?. Just remove or comment out the code in your original file, that will stop it overriding your new file. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now