关于 php:如何在另一个 .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 文件

1
2
3
4
5
<?php

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

    ?>

  • 感谢您的回复,实际上我想在我的自定义主题 .phtml 文件中访问基本主题 .phtml 文件。您对此有任何想法吗?
  • 复制基本主题文件夹以粘贴到您当前的主题中,它将正常工作
  • 实际上,基本主题与回退逻辑一起使用,因此只需将基本主题文件移动到您当前的主题。
  • 我将基本主题文件移动到我的主题相同的文件结构中,并使用了上面的代码,但它不起作用。我的页面出现以下错误。处理您的请求时出现错误 Invalid method Mage_Core_Block_Template::displayProductStockStatus(Array ( ) ) Trace:—–here 40 lines of stacktrace


要使用 getChildHtml() 来做到这一点,另一个 phtml 文件需要是您正在处理的块内的子块。
那段 xml 来自 app/design/frontend/yourtheme/layout/catalog.xml,在该块声明中,您将看到更多可以通过 getChildHtml() 调用的块。

1
2
3
<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>

在这种情况下,您可以像 getChildHtml(\\’related_products\\’) 那样在父块 view.phtml 中调用related-products.phtml。

  • 在我的主题中,我没有catalog.xml 文件,我在基本主题布局文件夹中有它。我可以在我的主题布局文件夹中创建catalog.xml 文件吗?


来源:https://www.codenong.com/22560323/

微信公众号
手机浏览(小程序)

Warning: get_headers(): SSL operation failed with code 1. OpenSSL Error messages: error:14090086:SSL routines:ssl3_get_server_certificate:certificate verify failed in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57

Warning: get_headers(): Failed to enable crypto in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57

Warning: get_headers(https://static.shanhubei.com/qrcode/qrcode_viewid_8747.jpg): failed to open stream: operation failed in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57
0
分享到:
没有账号? 忘记密码?