1

我正在为 Magento 编写一个自定义小部件。我已成功配置 - 文件ABC/DEF/Resources.php已加载并执行。

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

当包含在静态 CMS 块中时

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

一切正常返回

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

但是,当通过CMS->Widgets( Block Reference: Page Top) 包含时,结果是

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

有什么办法吗?

4

1 回答 1

2

通过CMS> 使用时,使用布局指令创建小部件,并使用节点Widgets设置所有特定数据(请参阅),这些节点在创建块之后执行(因此在调用之后)。actionMage_Widget_Model_Widget_Instance::generateLayoutUpdateXml()_prepareLayout()

在您的情况下,您可能更愿意使用_beforeToHtml()(就像一些基本的 Magento 小部件一样)。

于 2013-07-10T10:09:02.503 回答