2

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.

3

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)

  • Thanks a bunch this helped! May have one or two more questions later though :) – user9178 Jun 16 '14 at 9:47
  • Glad to hear that it helped you :) – Sukeshini Jun 16 '14 at 9:49
  • Ok so I now have: <sitetest> <class>Site_Test_Block</class> </sitetest> Within my ?showConfig=true...however I seem to be having trouble linking this to a custom XML layout. <block type="test/test" name="test" template="catalog/product/test.phtml" after="cms_page"> Sorry more tests than anything else lol – user9178 Jun 16 '14 at 9:54
  • The last test would be the .php file so ermm if I have this right.... <block type="modulename/filename"> – user9178 Jun 16 '14 at 10:00
  • Ok I think I've got it sorted however I have been given the following error when loading the page: Fatal error: Class 'Site_Test_Block_Test' not found in C:\wamp\www\magento\app\code\core\Mage\Core\Model\Layout.php on line 491 – user9178 Jun 16 '14 at 10:45

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.