简体   繁体   中英

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?

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?

Try this Code in your phtml file to call another phtml file

<?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. 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().

<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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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