Magento Certified Developer GuideCategory: 12. WidgetWhat classes are typically involved in Magento widget architecture
Manish Prakash Staff asked 5 years ago

In a typical widget structure the files which you need are (besides a standard magento module structure)

1. widget.xml
2. widget block file
3. source model for widget parameter options


<?xml version="1.0"?>
  <widget_unique_name type="unique/widget" translate="name description" module="excellence">
    <name>Sample Widget</name>
    <description>Sample Widget For Showing how widget works</description>
        <label>Link Options</label>

Frontend Block File For Display

//the below class also extend "Mage_Core_Block_Template" and then have the standard template file system
//instead of return html like below
class Excellence_Unique_Block_Widget extends Mage_Core_Block_Abstract implements Mage_Widget_Block_Interface {
  * Produce links list rendered as html
  * @return string
  protected function _toHtml() {
    $html = '';
    $param = $thisĀ­>getData('param1');
    return $param;

Options file

// app/code/local/Envato/WidgetLinks/Model/Options.php
class Excellence_Unique_Model_Options {
  * Provide available options as a value/label array
  * @return array
  public function toOptionArray() {
    return array(
      array('value' => 'print', 'label' => 'Hi'),
      array('value' => 'email', 'label' => 'Hello'),

We can also define a template file our widget. In our widget.xml file we need to write


and would widget block class should extend “Mage_Core_Block_Template”
this way we can directly use a template file