0

I have problem when I want to put JS into head when PHP condition is met, but I'm getting Mage_Core_Exception: Invalid block type excetion no idea why. I have read all the possible issues I have found but looks like there is ton of places I could go wrong and right now Im out of ideas.

I have config.xml where is my module declared. This is only part of it as rest of module is working, also JS and CSS I have in module_name.xml is working properly.

</frontend>
    <layout>
        <updates>
            <module_name>
                <file>module_name.xml</file>
            </module_name>
        </updates>
    </layout>
</frontend>

Then I have module_name.xml I understand that I say here "on checkout/cart page load this template/modulename/prependca.phtml into of page.

<checkout_cart_index translate="label">
    <reference name="head">
        <block type="namespace_moduleName/cart" name="prependca" template="modulename/prependca.phtml"/>
    </reference>
</checkout_cart_index>

Last, but not least, I have this Class of mine:

class Namespace_ModuleName_Block_Cart extends Mage_Checkout_Block_Cart_Abstract {

    public function prependCa() {
        $_quote = Mage::getSingleton('checkout/session')->getQuote();
        if (get_class($_quote) == Mage_Sales_Model_Quote) {
            $head = $this->getLayout()->getBlock('head');
            $head->addJs('namespace/modulenameTotals.js');
            $head->addItem('js', 'namespace/modulenameTotals.js');
        }
    }
}

From what I have read, I did all I had to do, however I still don't get results and only respond I get is Mage_Core_Exception: Invalid block type

  • did you try using core/template block? – Jaimin Sutariya Sep 24 '17 at 18:27
  • tried now, surprisingly still same... – JohnyProkie Sep 24 '17 at 19:13
0
  1. Go to app/design/frontend/{package}/{theme}/layout/local.xml then add this :

    <checkout_cart_index>
        <reference name="head">
            <action method="addItem"><type>skin_js</type><name>js/my-custom.js</name></action>
        </reference>
    </checkout_cart_index>
    
  2. Create your new js file in: skin/frontend/{package}/{theme}/js/my-custom.js then put your code inside.

  3. Now your js file will be just loaded in checkout/cart. Don't forget to clear the cache.


NB: I see some errors in your code:

1)

<frontend> // not </frontend>
    <layout>
        <updates>
            <module_name>
                <file>module_name.xml</file>
            </module_name>
        </updates>
    </layout>
</frontend>

2)

You can't load this type of block in a head ! but you can do it content, root etc...

If you need is to add a js file, follow my solution.

  • i tried changing from head to content or root, but still doesnt work. My main problem is that I cant use theme... – JohnyProkie Sep 25 '17 at 8:01
  • What kind of block do you want to add ?, it's a Js file ? – PЯINCƏ Sep 25 '17 at 8:02

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.