【发布时间】:2012-12-08 23:54:03
【问题描述】:
我正在为 Magento 开发 Slider 扩展,我希望能够在以下位置之一显示我的滑块:top_left、top_right、top_center、bottom_left/right/center!并且能够从我的管理员后端选择这个位置,比如 DropList 或类似的东西。 你能帮忙吗:)! 谢谢
【问题讨论】:
我正在为 Magento 开发 Slider 扩展,我希望能够在以下位置之一显示我的滑块:top_left、top_right、top_center、bottom_left/right/center!并且能够从我的管理员后端选择这个位置,比如 DropList 或类似的东西。 你能帮忙吗:)! 谢谢
【问题讨论】:
我找到的最佳解决方案是添加一个带有此事件的观察者:
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 的情况下获取和添加任何块。