I have a payment module that requires a bit of javascript on the checkout page for stores where it is enabled. The good news is that it is correctly including the link on the checkout page. Unfortunately, its also including the link on every other page and in every store.

How do you setup a javascript include to only appear in a certain section and only in stores where it is enabled?


If your module has a simple enable/disabled configuration setting for each store scope (which it seems to), you can use ifconfig, which is evaluated by Mage::getStoreConfigFlag():

<?xml version="1.0" encoding="UTF-8"?>
    <checkout_onepage_index><!-- the onepage checkout "page" -->
        <reference name="head"><!-- The HTML head block -->
            <action method="addJs" ifconfig="your/checkout_module/enabled">
                <js>your/file.js</js><!-- i.e. js/your/file.js -->

I built an observer which adds a layout handle, if

<?xml version="1.0"?>

And the observer:

class Namespace_MyModule_Model_Observer
     * add update handles
     * @param Varien_Event_Observer $observer
    public function controllerActionLayoutLoadBefore(Varien_Event_Observer $observer)
        /* @var $controller Mage_Core_Controller_Front_Action */
        $controller = $observer->getAction();
        $request = $controller->getRequest();

        /* @var $layoutUpdate Mage_Core_Model_Layout_Update */
        $layoutUpdate = $observer->getLayout()->getUpdate();

        // check whether to add the handle or not



Then you can add the JS to the handle and decide to add it or not.


Does this javascript is embedded within a layout file and the store have an appropriate theme? If this is the case, you can configure your application according with the following example: no need to define observer, to overload, no customizations:

imagine your module come from the a layout handle mymodulelayout.xml

you should have app/design/frontend/base/default/layout/mymodulelayout.xml

move this file only on the store where you wants to enable this module:


this layout will be used only when yourwebsite package is applied and your theme is applied, so for your store where you wants to load this elements in checkout.


  • Its a good idea, but unfortunately doesn't work in my case. We're doing a multisite setup for several different regions and we want to be able to enable and disable modules independently of the theme. Feb 26 '13 at 22:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.