Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

eCommerce Tycoon


You are currently viewing our eCommerce Tycoon as a guest. Please register to participate.
Login



Reply
PrestaShop - how to add additional JScript / CSS files to a theme
Old 02-21-2012, 09:41 PM PrestaShop - how to add additional JScript / CSS files to a theme
TWD
TWD's Avatar
King Spam Talker

Posts: 1,183
Trades: 0
My first thought on this was to hack the "header.tpl" file and add the new files that way.
That route may indeed work but there is a smarter way to do it.
I believe the benefit of doing things the "smart" way is that it will get your new files cached on the server thereby speeding up load times.

Anyway, PrestaShop 1.4 and up has an "overrides" directory containing the subdirectories "classes" and "controllers".

First of all you need to work out where you want to add in your new files. For example if you only want to add your scripts on the Category pages you'll need to find a file called CategoryController.php and save it (using the same name) into overrides/controllers.

If you want to add a script that applies to every page, I believe FrontController.php is the one you are looking for, although (confusingly) this goes into overrides/classes.

What you need to do with each of those files is extend the original CORE classes like this:

Code:
<?php

class FrontController extends FrontControllerCore
{

    public function setMedia()
    {
            parent::setMedia();
            Tools::addJS(_THEME_JS_DIR_.'myhacks.js');
    }

}
or like this

Code:
<?php

class CategoryController extends CategoryControllerCore
{

    public function setMedia()
    {
    
        parent::setMedia();
        Tools::addJS(_THEME_JS_DIR_.'myhacks_category.js');
    
    }

}
NOTE: Do NOT close the php opening tag. I believe PrestaShop automatically does something to trim out any white space that could cause problems and closes the tag automatically. This is something the Drupal does too.
__________________
RATE-MY-WEBSITE.com "Free website reviews by real web professionals"
Please login or register to view this content. Registration is FREE

Last edited by TWD; 02-22-2012 at 02:57 AM..
TWD is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Reply     « Reply to PrestaShop - how to add additional JScript / CSS files to a theme
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.17777 seconds with 12 queries