示例:名为 ajaxhandlerController 的 Controller 它可以接收多种ajax请求类型, 每种类型都应该在布局 xml 中有单独的 block
在ajaxhandler索引的布局中我会写
<mymodule_ajaxhandler_index>
<block some block></block>
</mymodule_ajaxhandler_index>
如何从索引更改为保存,例如如果有 $request['type']=="save";所以我可以使用
<mymodule_ajaxhandler_save>
最佳答案
我会忘记布局 XML。只需实例化一个 Core_Block_Html_Template 并根据收到的请求类型使用 setTemplate 方法分配正确的模板即可。
$html = $this->getLayout()
->createBlock('core/template')
->setTemplate('your/template.phtml')
->toHtml();
关于php - Magento:如何在 Controller 中动态更改默认模板,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7025314/