How to create your own custom block in Magento

4 minute read

Step 1: Global Module Configuration

Create your custom block configuration xml file inside the app/etc/modules/ directory. I named mine Gravitywell_All.xml.

Step 2: Directories

Create the correct directories for your module:

Step 3: Module Configuration

Add your module configuration file. This should be named config.xml and placed inside app/code/local/Gravitywell/Example/etc.

Step 4: Create the Block Class

Now you can create your block class. In this example we'll called the block simply Menu.php and place it inside app/code/local/Gravitywell/Example/Block.

Step 5: Create the view script

Create a view script template file to use for your block. I'm simply going to place this as a file called menu.phtml inside the folder app/design/frontend/gravitywell/example/template/gravitywell.

Step 6: Embed the block inside your layout.xml or programmatically.

Written by Simon Bos (Founder/Director). Read more in Insights by Simon or check our their socials Twitter, Instagram