Shakti Singh
Shakti Singh

Reputation: 86386

Adding Block in existing module of magento

I have customized customer module to meet my requirement. I am able to rewrite block classes of customer module. I am trying to add one custom block class in this module which is not exists in existing customer module but I don't know how to accomplish this.

my code looks like in config.xml

 <blocks>            
        <customer>
           <rewrite>                          
<widget_name>Mynamespace_Customer_Block_Widget_Name</widget_name>                   
<form_register>Mynamespace_Customer_Block_Form_Register</form_register>
<form_edit>Mynamespace_Customer_Block_Form_Edit</form_edit>
           </rewrite>                   
        </customer>  

     </blocks>

I created a new block class under the Form directory of customer module called 'Test.php'

And customer layout file looks like

<reference name="my.account.wrapper">
            <block type="customer/form_test" name="customer_test" template="customer/form/test.phtml"/>
        </reference>   

But it is not executing the block class file. Is there anything should be added in config.xml file of this module?

Please help how this block can be integrated with existing module.

Thanks.

Upvotes: 1

Views: 3235

Answers (2)

Joe Mastey
Joe Mastey

Reputation: 27119

You shouldn't really be adding blocks to the customer module, you should be adding them to your own module. If you want to keep on w/ the customer module, check to make sure that your block is named as Mage_Customer_Block_Form_Test and extends Mage_Core_Block_Template. Otherwise, create the class as Mynamespace_Customer_Block_Form_Test and keep it in your module directory. Then, add a block definition for your class in config.xml:

<blocks>
  <mynamespace_customer>
    <class>Mynamespace_Customer_Block</class>
  </mynamespace_customer> 
</blocks>

Then you should be able to load the block as mynamespace_customer/form_test.

It may be easier to debug your problem if you use a module name other than customer. Generally speaking, that is a bad idea and will likely cause bugs in the system.

Hope that helps!

Thanks, Joe

Upvotes: 4

clockworkgeek
clockworkgeek

Reputation: 37700

You may already be aware of this but think about checking LayoutViewer to see what the layout thinks it is using.

Although I'm sure your example config.xml is just an example please make sure that you've remembered to create a rewrite for form_test and that there is a valid blocks section for your own module.

BTW, LayoutViewer could really do with being packaged properly for Magento Connect. The linked file lacks the necessary config to enable the module and it would be much more useful if accessible from PEAR.

Upvotes: 2

Related Questions