1

我在 Magento 中有一个自定义管理配置字段类型,我想为该配置字段加载一个 CSS 文件(也是 javascript)。

字段类:

class Company_Module_Block_Configure extends Mage_Adminhtml_Block_System_Config_Form_Field
{

    protected function _getElementHtml(Varien_Data_Form_Element_Abstract $element)
    {
        // I would like to load the CSS and Javascripts files to the head.
        return "Here comes the field output";
    }
}

我试过这个,但没有运气。也许头部渲染得更快:

Mage::app()->getLayout()->getBlock('head')->addCss('My css url...');

或者我应该以某种方式观察某种“before_body_end”事件。可能吗?

更新#1:

我已经开始经历 before_body_end 事件:

配置文件

<config>
   <global>
       <events>
            <core_block_abstract_to_html_before>
                <observers>
                    <test>
                        <class>Company_Module_Model_Observer</class>
                        <method>test</method>
                    </test>
                </observers>
            </core_block_abstract_to_html_before>
        </events>
    </global>
</config>

观察到的方法如下所示:

public function test($block){
    if($block->getEvent ()->getBlock()->getNameInLayout() == 'before_body_end'){

    }
}
4

0 回答 0