aaronjpitts Posted August 15, 2014 Share Posted August 15, 2014 Hi guys, I have a JS file I only want to include on the homepage, by creating an override for the setMedia function in FrontController. But I only want to include it on the homepage, how can I target that? Thanks Link to comment Share on other sites More sharing options...
El Patron Posted August 15, 2014 Share Posted August 15, 2014 I think you should just use displayHome in your module, then use addJS for that hook. overrides should only be used when there is no other way... then in module hook $this->context->controller->addJS(trim($jsfile)); Link to comment Share on other sites More sharing options...
aaronjpitts Posted August 15, 2014 Author Share Posted August 15, 2014 (edited) Thanks for your suggestion, but it is not for a module. I simply want to include a JS file that is needed only for the homepage. I know how to do this by adding the JS file and targeting it in the header.tpl file with smarty, but then the JS file isn't included in the CCC JS cache. Hence why I need to add it via the FrontController. Edited August 15, 2014 by aaronjpitts (see edit history) Link to comment Share on other sites More sharing options...
El Patron Posted August 15, 2014 Share Posted August 15, 2014 Thanks for your suggestion, but it is not for a module. I simply want to include a JS file that is needed only for the homepage. I know how to do this by adding the JS file and targeting it in the header.tpl file with smarty, but then the JS file isn't included in the CCC JS cache. the recommended method is to use module approach. there are pre-built modules that will do this for you. is this a hack just for your shop or something you plan on distributing later? Link to comment Share on other sites More sharing options...
aaronjpitts Posted August 15, 2014 Author Share Posted August 15, 2014 (edited) It's just a simple hack for a custom theme I've made for a client (for a simple slideshow), nothing to distribute. Is there any way I can just do this as an override, seems overkill otherwise just for one script. Thanks Edited August 15, 2014 by aaronjpitts (see edit history) Link to comment Share on other sites More sharing options...
El Patron Posted August 15, 2014 Share Posted August 15, 2014 then as suggested, since you are doing the work for someone else (hence distributed) that you use best practice, create little module to add the .js. you are only talking a couple minutes to create. in the override you would not know when just home page is being displayed...so that's a dead end. Link to comment Share on other sites More sharing options...
aaronjpitts Posted August 15, 2014 Author Share Posted August 15, 2014 Ok, I'll have to go the module route. You say there are some pre-built ones for this purpose? I couldn't fine one just now, could you please link to one I could use this for? Thanks for your help Link to comment Share on other sites More sharing options...
El Patron Posted August 15, 2014 Share Posted August 15, 2014 I can not recommend any one module...this you can search on...probably time spent looking you could create this simple module. best of luck 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