alumi Posted November 30, 2012 Share Posted November 30, 2012 (edited) Hi, This is my first post in this forum I have been working with Prestashop a lot, and it was a good experience. Thanks for giving it for free When I develop a module, I found something inconvenient. In a module, I only use hookHome (to output things to homepage) and hookHeader (to include needed CSS/JS). But in this way, the CSS/JS files are included in every page. This is not optimized. I surely can include CSS/JS files in the hookHome, but you know, it is not standard. I doubt that Prestashop might have a way to work around with this. Do you have any suggestion? Edited December 11, 2012 by alumi (see edit history) Link to comment Share on other sites More sharing options...
math_php Posted November 30, 2012 Share Posted November 30, 2012 Hi alumi, Perhaps by using hookHeader like this public function hookHeader(){ global $smarty if ($smarty->page_name == 'index'){ Tools::addCSS(($this->_path)._THEME_CSS_DIR_.'product_list.css', 'all'); } } But I have a problem to get page_name value in $smarty Link to comment Share on other sites More sharing options...
math_php Posted November 30, 2012 Share Posted November 30, 2012 An other solution, (a working one) would be to use $fileName = basename($_SERVER['SCRIPT_FILENAME']); Thanks for you question, it helped me to find a solution. Link to comment Share on other sites More sharing options...
alumi Posted November 30, 2012 Author Share Posted November 30, 2012 (edited) Hi alumi, Perhaps by using hookHeader like this public function hookHeader(){ global $smarty if ($smarty->page_name == 'index'){ Tools::addCSS(($this->_path)._THEME_CSS_DIR_.'product_list.css', 'all'); } } But I have a problem to get page_name value in $smarty Yes, you can do it like this: public function hookHeader(){ global $smarty; $page_name = $smarty->get_template_vars('page_name'); if ($page_name == 'index'){ Tools::addCSS(($this->_path)._THEME_CSS_DIR_.'product_list.css', 'all'); } } And thank you for pointing out the Smarty page_name variable XD ! Edited November 30, 2012 by alumi (see edit history) 1 Link to comment Share on other sites More sharing options...
math_php Posted November 30, 2012 Share Posted November 30, 2012 get_template_vars seems to be deprecated. I found getTemplateVars wich works fine. What about a 'solved' ? Cheers 1 Link to comment Share on other sites More sharing options...
jorgemartin Posted January 28, 2013 Share Posted January 28, 2013 (edited) Have you tried? public function hookHeader(){ if (Tools::getValue('controller') == 'index'){ Tools::addCSS(($this->_path)._THEME_CSS_DIR_.'product_list.css', 'all'); } } Edited January 28, 2013 by jorgemartin (see edit history) 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