0

I have an extension that is structured like this:

Myextension
└── Mymodule
    └── etc
    │   └── config.xml
    └── Helper
        └── Data.php

The data extends Mage_Core_Helper_Abstract and has this method which returns some HTML:

public function sayHi()
{
    return 'Hello world!';
}

My question

Is it possible to provide a way so that sayHi can be called from what ever theme or template (like product page) using the widget in the admin?

Should I create a block/filter/widget?

Does Magento have some hook system?

I read lot of documentation/tutorial/book but I couldn't grasp the Magento workflow for such things.

2

Here is a nice tutorial that shows you how to create widgets
You will need a block that implements the interface Mage_Widget_Block_Interface. The interface contains 3 methods. If your block extends Mage_Core_Block_Abstract or Mage_Core_Block_Template you should be ok. Those blocks already contain the methods.
This block can do anything you want (including calling your helper method). It acts as all the other blocks in Magento.
Then you will need to create a widget.xml file in the etc folder of your extension where you define the widget.
You specify in this file the widget code as a tag (it has to be unique over all Magento otherwise you just override an existing widget). On this tag define an attribute type with the block alias, then in a subtag add the name and the description of your widget and any parameters it may have.
When you are done, clear the cache and your widget should appear in the widgets dropdown when you try to add a widget to a page.

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.