0

I have a very basic module:

app/code/local/Demo/Custom/Block/Giftproducts.php

class Demo_Custom_Block_Giftproducts extends Mage_Core_Block_Template {

  public function getGiftProducts() {   
    //code omitted
  }

}

app/code/local/Demo/Custom/etc/config.xml

<?xml version="1.0"?>
<config>
  <modules>
    <Demo_Custom>
      <version>1.0.0</version>
    </Demo_Custom>
  </modules>
  <global>
    <blocks>
      <giftproducts>
        <class>Demo_Custom_Block</class>
      </giftproducts>
    </blocks>
  </global>
</config>

app/design/frontend/custom_theme/default/layout/custom.xml

<?xml version="1.0" ?>
<layout>
    <default>
        <reference name="content">
        </reference>
    </default>
    <checkout_cart_index>
        <reference name="checkout.cart">
            <block type="custom/giftproducts" name="giftproducts" template="custom/giftproducts.phtml" />
        </reference>
    </checkout_cart_index>
</layout>

app/etc/modules/Demo_Custom.xml:

<?xml version="1.0"?>
<config>
    <modules>
        <Demo_Custom>
            <active>true</active>
            <codePool>local</codePool>
        </Demo_Custom>
    </modules>
</config>

app/design/frontend/custom_theme/default/tempalte/custom/giftproducts.phtml:

<?php

echo 'got here';

In cart.phtml I then call the block like this:

<?php echo $this->getChildHtml('giftproducts') ?>

Everything is doublechecked, seems pretty clear, cache is cleared, however I just cannot get the template to bo executed. tired various combinations of declaration in xml file, but with no luck.

Any help or guidance is much appreciated.

2

app/code/local/Demo/Custom/etc/config.xml

<?xml version="1.0"?>
<config>
    <modules>
        <Demo_Custom>
            <version>1.0.0</version>
        </Demo_Custom>
    </modules>
    <global>
        <helpers>
            <custom>
                <class>Demo_Custom_Helper</class>
            </custom>
        </helpers>
        <blocks>
            <custom>
                <class>Demo_Custom_Block</class>
            </custom>
        </blocks>
    </global>
    <frontend>
        <layout>
            <updates>
                <demo_custom>
                    <file>demo_custom.xml</file>
                </demo_custom>
            </updates>
        </layout>
    </frontend>
</config>

app/design/frontend/{package}/{theme}/layout/demo_custom.xml

<?xml version="1.0"?>
<layout>
    <checkout_cart_index>
        <reference name="root">
            <block type="custom/giftproducts" name="custom.giftproducts" template="custom/giftproducts.phtml" />
        </reference>
    </checkout_cart_index>
</layout>

app/design/frontend/{package}/{theme}/template/custom/giftproducts.phtml:

<?php echo $this->__('We got it'); ?>

app/code/local/Demo/Custom/Helper/Data.php

<?php
class Demo_Custom_Helper_Data extends Mage_Core_Helper_Abstract
{

}

cart.phtml

<?php echo $this->getBlockHtml('custom.giftproducts'); ?>

app/etc/modules/Demo_Custom.xml:

<?xml version="1.0"?>
<config>
    <modules>
        <Demo_Custom>
            <active>true</active>
            <codePool>local</codePool>
        </Demo_Custom>
    </modules>
</config>
1

Your code seems correct, but you have not defined XML file for the layout in app/code/local/Demo/Custom/etc/config.xml.

Please define layout tag in config.xml file like below:

<layout>
    <updates>
        <custom>
            <file>custom.xml</file>
        </custom>
    </updates>
</layout>

Update: One more problem I have found that you have defined block class name as giftproducts:

<blocks>
  <giftproducts>
    <class>Demo_Custom_Block</class>
  </giftproducts>
</blocks>

but called it in custom.xml with:

<block type="custom/giftproducts" name="giftproducts" template="custom/giftproducts.phtml" />

which should be:

<block type="giftproducts/giftproducts" name="giftproducts" template="custom/giftproducts.phtml" />

in your case.

I think this should do the trick.

  • Very to the point answer. Will try as soon as I can. – Domas Dec 6 '17 at 13:38
  • @Domas, have you tried above solution?? – Mohit Kumar Arora Dec 8 '17 at 8:21
  • Yes, I have, however, the solution that was selected as the correct answer was the one that worked. – Domas Dec 9 '17 at 10: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.