Bart Platak
Bart Platak

Reputation: 4475

Accessing widget's parameters in _prepareLayout

I'm writing a custom widget for Magento. I have it successfully configured - file ABC/DEF/Resources.php is loaded and executed.

class ABC_DEF_Block_Resources extends Mage_Core_Block_Abstract implements Mage_Widget_Block_Interface{
    protected function _prepareLayout(){
        var_dump($this->getData());
    }
}

When included in a static CMS block via

{{widget type="def/resources" res="css:test.css"}}

everything works fairly well returning

array(2) { ["type"]=> string(15) "def/resources" ["res"]=> string(11) "css:test.css" }

However, when included via CMS->Widgets (Block Reference: Page Top), the result is

array(1) { ["type"]=> string(15) "def/resources" }

Any way around it?

Upvotes: 1

Views: 217

Answers (1)

blmage
blmage

Reputation: 4214

When used via CMS > Widgets, widgets are created with layout instructions, and all the specific data are set using action nodes (see Mage_Widget_Model_Widget_Instance::generateLayoutUpdateXml()), which are executed after the block is created (so after the call to _prepareLayout()).

In your case, you may rather want to use _beforeToHtml() (as do some of the base Magento widgets).

Upvotes: 2

Related Questions