【问题标题】:Displaying my Bloc in mutiple "zone"?在多个“区域”中显示我的块?
【发布时间】:2012-12-08 23:54:03
【问题描述】:

我正在为 Magento 开发 Slider 扩展,我希望能够在以下位置之一显示我的滑块:top_left、top_right、top_center、bottom_left/right/center!并且能够从我的管理员后端选择这个位置,比如 DropList 或类似的东西。 你能帮忙吗:)! 谢谢

【问题讨论】:

    标签: magento layout adminhtml


    【解决方案1】:

    我找到的最佳解决方案是添加一个带有此事件的观察者:

    controller_action_layout_load_before

    然后我们在其中加载布局:

    public function addBlock(Varien_Event_Observer $observer)
    {
       $layout = $observer->getEvent()->getLayout()->getUpdate();
       $layout->addHandle(ThePositionYouWant);
       return $this;
    }
    

    在你的布局中放置你想要的不同位置:

    <position_name>
        <reference name="content">
            <block type="BlockName" name="Name" before="-" template="YourBlockTemplate"/>
         </reference>
    </position_name>
    
        <position_name2>
            <reference name="left">
                <block type="BlockName" name="Name" after="-" template="YourBlockTemplate"/>
             </reference>
        </position_name2>
    

    而且它有效。 希望这会有所帮助:)!

    【讨论】:

    • 聪明的解决方案。当然,一旦您拥有$layout,您就可以在不使用 XML 的情况下获取和添加任何块。
    猜你喜欢
    • 2021-09-30
    • 1970-01-01
    • 1970-01-01
    • 2018-06-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-01-29
    • 1970-01-01
    相关资源
    最近更新 更多