Magento CMS Page – Add Custom Module

cmslayoutmagento-1.7magento-1.8

I have a custom module. I need to add it in home page of my site. I have added block in the content section of my home page. But it didn't display anything. I have also tried the layout part of home page and the result is as in the previous case. These are my codes

app/code/local/Karaokeshop/Banner/etc/config.xml

<config>
<modules>
    <Karaokeshop_Banner>
        <version>0.1.0</version>
    </Karaokeshop_Banner>
</modules>
<frontend>
    <routers>
        <banner>
            <use>standard</use>
            <args>
                <module>Karaokeshop_Banner</module>
                <frontName>banner</frontName>
            </args>
        </banner>
    </routers>
    <layout>
        <updates>
            <banner>
                <file>banner.xml</file>
            </banner>
        </updates>
    </layout>
</frontend>
<admin>
    <routers>
        <banner>
            <use>admin</use>
            <args>
                <module>Karaokeshop_Banner</module>
                <frontName>banner</frontName>
            </args>
        </banner>
    </routers>
</admin>
<adminhtml>
    <menu>
       <!-- <banner module="banner">-->
       <cms>
            <title>CMS</title>
            <sort_order>71</sort_order>
            <children>
                <items module="banner">
                    <title>Manage Banner</title>
                    <sort_order>0</sort_order>
                    <action>banner/adminhtml_banner</action>
                </items>
            </children>
        </cms>
        <!--</banner>-->
    </menu>
    <acl>
        <resources>
            <all>
                <title>Allow Everything</title>
            </all>
            <admin>
                <children>
                    <Karaokeshop_Banner>
                        <title>Banner Module</title>
                        <sort_order>10</sort_order>
                    </Karaokeshop_Banner>
                </children>
            </admin>
        </resources>
    </acl>
    <layout>
        <updates>
            <banner>
                <file>banner.xml</file>
            </banner>
        </updates>
    </layout>
</adminhtml>

<global>
    <models>
        <banner>
            <class>Karaokeshop_Banner_Model</class>
            <resourceModel>banner_mysql4</resourceModel>
        </banner>
        <banner_mysql4>
            <class>Karaokeshop_Banner_Model_Mysql4</class>
            <entities>
                <banner>
                    <table>banner</table>
                </banner>
            </entities>
        </banner_mysql4>
    </models>
    <resources>
        <banner_setup>
            <setup>
                <module>Karaokeshop_Banner</module>
            </setup>
            <connection>
                <use>core_setup</use>
            </connection>
        </banner_setup>
        <banner_write>
            <connection>
                <use>core_write</use>
            </connection>
        </banner_write>
        <banner_read>
            <connection>
                <use>core_read</use>
            </connection>
        </banner_read>
    </resources>
    <blocks>
        <banner>
            <class>Karaokeshop_Banner_Block</class>
        </banner>
    </blocks>
    <helpers>
        <banner>
            <class>Karaokeshop_Banner_Helper</class>
        </banner>
    </helpers>
</global>
</config>

This is the code I have tried in the content section of home CMS page

{{block type="banner/banner" name="home_banner" template="banner/homenewpro.phtml"}}

This is the code I have tried in the layout part(within content section) of home CMS page.

<block type="banner/banner" name="home_banner" template="banner/banner.phtml" />

What is the problem with this code? What I have made wrong with these codes? Help me guys…. Thanks in advance..

Best Answer

First of all make sure the file Karaokeshop/Banner/Block/Banner.php exists and contains this class.

class Karaokeshop_Banner_Block_Banner extends Mage_Core_Block_Template{
   //class methods here
}

also make sure the template banner/homenewpro.phtml exists in app/design/frontend/{package}/{theme}/template.
Just to make sure, you can place it in app/design/frontend/base/default/template.

I hope you also created the declaration file app/etc/modules/Karaokeshop_Banner.xml with this content.

<?xml version="1.0"?>
<config>
    <modules>
        <Karaokeshop_Banner>
            <codePool>local</codePool>
            <active>true</active>
            <depends>
                <Mage_Core />
            </depends>
        </Karaokeshop_Banner>
    </modules>
</config>

Clear the cache, disable the compilation and give it an other try.

You can also enable the logging from System->Configuration->Developer and check var/log for any errors.