是否厌倦了用xml文件来做Magento的页面布局,是的话来试试下面这种方式,把布局代码写到controller 里面
public function mycoolAction() { /* ... Some code ...*/ $update = $this->getLayout()->getUpdate(); /* ... Some code ...*/ $this->addActionLayoutHandles(); /* ... Some code ...*/ $this->loadLayoutUpdates(); /* ... Some code ...*/ /* My stuff, add pure XML like you do from XML layout files <img src="http://inchoo.net/wp-includes/images/smilies/icon_smile.gif" mce_src="http://inchoo.net/wp-includes/images/smilies/icon_smile.gif" alt=":)" class="wp-smiley"> */ $update->addUpdate(' <reference name="head"> <action method="addJs"><mce:script type="text/javascript"><!-- varien/product.js // --></mce:script></action> <action method="addItem"><type>js_css</type><name>calendar/calendar-win2k-1.css</name><params /><!--<if/><condition>can_load_calendar_js</condition>--></action> <action method="addItem"><type>js</type><name>calendar/calendar.js</name><!--<params/><if /><condition>can_load_calendar_js</condition>--></action> <action method="addItem"><type>js</type><name>calendar/calendar-setup.js</name><!--<params/><if /><condition>can_load_calendar_js</condition>--></action> <action method="addItem"><type>skin_js</type><name>js/bundle.js</name></action> </reference> '); /* ... Some code ...*/ $this->generateLayoutXml()->generateLayoutBlocks(); /* ... Some code ...*/ $this->renderLayout(); }
这样你也许就可以少新建一些xml文件
当然,这里还是推荐把布局写在xml文件里,上面这种方式只是告诉你Magento还有另一种方式来实现相同的功能