我尝试寻找解决方案但没有结果。
我的任务是编写模块。它应该将一些 html 插入现有块中。
我注意到,当我使用布局 .xml 文件时,我可以将我的块插入到一些参考中,例如
<reference name="product.info">
<block type='googlethis/link' name="googlethis"
template="catalog/product/googlethis.phtml"/>
</reference>
我的区块也显示了。
在其他情况下我应该打电话getChildHtml()
方法,但它不好,因为它会更改模板 .phtml 文件。
那么有没有办法将我的 phtml 块插入到any其他 phtml 块而不调用getChildHtml()
?
有一种方法可以做到这一点,尽管它不是一个完全优雅的解决方案。但它在大多数情况下都有效,并且有时也被证明是有用的。
基本上,想法是替换您想要在布局 XML 中之前/之后渲染块的块,将该块作为子块放置在您的块中,然后在您的块之前/之后渲染它的输出。
假设您想在购物车详细信息页面上的总计块之前输出一个块,您可以在扩展程序的layout.xml 中执行以下操作
<checkout_cart_index>
<reference name="checkout.cart">
<block type="myextension/block" name="myextension.block" as="myextension_block" template="myextension/template.phtml">
<action method="setChild"><name>totals</name><block>totals</block></action>
</block>
<action method="setChild"><name>totals</name><block>myextension.block</block></action>
</reference>
</checkout_cart_index>
然后在你的 template.phtml 文件中你将有:
<div id="myextension">
// Your template code
</div>
// Render the totals block that you placed inside your block
<?php echo $this->getChildHtml('totals'); ?>
正如我所说,这并不适合所有情况,也不是非常优雅,但它确实有效。
Jon
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)