how to write a custom block in Magento Commerce CMS ?

magento

Magento - Open Source eCommerce

Magento Commerce is a powerful and scalable online shopping system (or Shopping cart + CMS).

It is developed using PHP with MVC (Model-View-Controller) framework. If you are not familiar with MVC framework it will take a long time for you to create custom block or fuction in Magento System.

Here are the 5 simple steps to demostrate how to create a custom block in Magento.

Step 1.) Creates your custom block file Customblock.xml into /app/etc/modules/ directory.

Code :

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

** If your custom name = CustomBlock , you attribute should be <Mage_Custom_Block>**

Step 2.) Creates config.xml into /app/code/local/Mage/Customblock/etc/ directory

*Note : you have to create your custom block folder personally, eg, creates “Customeblock” folder.

<?xml version="1.0"?>
<config>
  <global>
    <blocks>
      <backlink>
        <class>Mage_Backlink_Block</class>
      </backlink>
    </blocks>
  </global>
</config>

Step 3.) Creates your custom PHP script into /app/code/local/Mage/Customblock/Block/<function name>.php

Content :

class Mage_Backlink_Block_Listing extends Mage_Core_Block_Abstract
{
  protected function _toHtml()
  {
        //$P=$this->getRequest()->getParams();
        //$pageid =isset( $P['pid'] )?$P['pid']*1:0;
     return $html;
  }
}

Step 4.) Goto Magento Admin page, from the menu toolbar, choose CMS -> Manage Pages, Choose the page you want to edit, the paste the code into the content.

{{block type="backlink/listing" pid="6" }}
Creates Backlink.xml into /app/etc/modules/

无觅相关文章插件,快速提升流量

This entry was posted in Programming and tagged , , . Bookmark the permalink.

4 Responses to how to write a custom block in Magento Commerce CMS ?

  1. internetno oglaševanje says:

    Excelent! i dont know why Magento documentation is so bad, I have to learn it from blogs like yours. Do you know any good reference book worth buying it?

    Thanks!

  2. Sam Dufel says:

    It’s a nice article, but I see all the html special characters double-escaped – everything looks like & < etc. Makes it painful to read…

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>