Jump to content

[solved] add CSS/JS to HEAD inside a module


alumi

Recommended Posts

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 by alumi (see edit history)
Link to comment
Share on other sites

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

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 by alumi (see edit history)
  • Like 1
Link to comment
Share on other sites

  • 1 month later...

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...