Jump to content

Howto cleanly add module on certain page ?


Recommended Posts

As stated in the title, i would like to know what is the best (? cleanest) way, to set a module and have it loaded only on certain pages, for instance, on homepage ONLY.


My problem, is i use several modules with js (sometimes big), but not on the same pages, so i would like to speed the page loading.


I'm aware that

1) i can add in the template a condition like :

{if $page_name == 'index'}

but in that case, only the code in between is conditionnal : the js and css are loaded anyway within the



public function hookHeader($params)
Tools::addCSS(_MODULE_DIR_.'mymodule.css', 'all');
Tools::addJS(_MODULE_DIR_.'mymodule.js', 'all');

And it could be very heavy and generating errors since the html the js is working on is not here.


2) I could EXCLUDE pages from the position management but is it really the best way ? I should exclude ALL pages but one ! And i'm not sure either the js won't be loaded.


=> I understand the separation of the code itself and the position it's html is displayed, but is there's a way to add in the hookHeader function for instance, a condition saying "add js and css only if this page" ?


Thank you in advance

Link to comment
Share on other sites

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...