簡體   English   中英

如何在另一個.phtml文件magento中訪問一個.phtml文件?

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM