Magento Custom Module – Blocks and config.xml Help

blocksconfigurationmagento-1.9module

I have created a custom module but having a little difficulty with blocks in the config.xml

For some reason I'm not able to get the blocks to show on the dump of all the xml…maybe I've missed something?

I have the following structure:

app\code\local\Site\SiteTest\etc\config.xml

app\code\local\Site\SiteTest\Block\test.php

<?xml version="1.0" encoding="UTF-8"?>
<config>
    <modules>
        <Site_Test>
            <version>1.0.0</version>
        </Site_Test>
    </modules>  
    <global>
        <blocks>
            <highest>
                <class>Site_Block</class>
            </highest>
        </blocks>
    </global>
</config>

I am trying to link this to a custom layout for example:

<block type="sitetest/test" name="home.catalog.product.test" template="catalog/product/test.phtml" after="cms_page">

If anyone could shed some light on this would really be appreciated.

Best Answer

Since you have provided less info about your module I can suggest the following corrections only. Hope it might useful.

1). There are some mis-configurations in your config.xml file. See the below code (corrected one)

<?xml version="1.0" encoding="UTF-8"?>
<config>
    <modules>
        <Site_SiteTest><!--use 'Namespace_Module' -->
            <version>1.0.0</version>
        </Site_Test>
    </modules>  
    <global>
        <blocks>
            <sitetest> <!-- this node can be anything, But as standard use the lowercase name of your module-->
                <class>Site_SiteTest_Block</class><!-- put entire path upto Block folder-->
            </sitetest>
        </blocks>
    </global>
</config>

2). Rename your block class file as Test.php

So the block class declaration should be as follow.

<?php
class Site_SiteTest_Block_Test extends Mage_Core_Block_Template
{
//your code here.
}

3). Make sure you have written the module activation file in app/etc/modules folder. It should be Site_SiteTest.xml with the following content.

<config>
   <modules>
      <Site_SiteTest>
          <active>true</active>
          <codePool>local</codePool>
      </Site_SiteTest>
   </modules>
</config>

4). Make sure the cache is disabled. (go to System > Cache Management and select all, then disabled them)