[英]How to acces one .phtml file in another .phtml file magento?
在magento开发中,如何访问一个或多个其他“ .phtml”文件中的一个“ .phtml”文件?
例如:
在我的主题模板文件夹中,有一个文件夹信息。 它包含info.phtml.info.phtml显示数据库中的数据。我想通过使用getChildHtml()在其他.phtml文件中使用此info.phtml。
在您的phtml文件中尝试此代码以调用另一个phtml文件
<?php
echo $this->getLayout()->createBlock('core/template')->setTemplate('test/test.phtml')->toHtml();
?>
要使用getChildHtml()做到这一点,另一个phtml文件必须是您正在处理的块内的子块。 那段xml来自app / design / frontend / yourtheme / layout / catalog.xml,在该块声明内,您将看到可以通过getChildHtml()调用的更多块。
<block type="catalog/product_view" name="product.info" template="catalog/product/view.phtml">
<block type="catalog/product_list_related" name="product.related.products" as="related_products" template="catalog/product/view/related-products.phtml"/>
</block>
在这种情况下,您可以在父块view.phtml内调用诸如getChildHtml('related_products')之类的related-products.phtml。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.