简体   繁体   English

如何在另一个.phtml文件magento中访问一个.phtml文件?

[英]How to acces one .phtml file in another .phtml file magento?

In magento development how to access one ".phtml" file in one or more other ".phtml" files? 在magento开发中,如何访问一个或多个其他“ .phtml”文件中的一个“ .phtml”文件?

For example: 例如:

In my theme template folder there is one folder info. 在我的主题模板文件夹中,有一个文件夹信息。 It contains info.phtml.This info.phtml display data from database.I want to use this info.phtml in my other .phtml files by using getChildHtml() how to do this? 它包含info.phtml.info.phtml显示数据库中的数据。我想通过使用getChildHtml()在其他.phtml文件中使用此info.phtml。

Try this Code in your phtml file to call another phtml file 在您的phtml文件中尝试此代码以调用另一个phtml文件

<?php

    echo $this->getLayout()->createBlock('core/template')->setTemplate('test/test.phtml')->toHtml();

    ?>

To do that using getChildHtml() the other phtml file needs to be child block inside of the block you are working on. 要使用getChildHtml()做到​​这一点,另一个phtml文件必须是您正在处理的块内的子块。 That piece of xml came from app/design/frontend/yourtheme/layout/catalog.xml, inside that block declaration you will see more blocks that can be called via getChildHtml(). 那段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>

In this case you can call related-products.phtml like that getChildHtml('related_products'), inside of the parent block view.phtml. 在这种情况下,您可以在父块view.phtml内调用诸如getChildHtml('related_products')之类的related-products.phtml。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM