【发布时间】:2019-07-28 04:58:40
【问题描述】:
我正在尝试从自定义模块在产品页面中添加一个静态块部分,但无法正常工作。 product.phtml 模板文件调用无法从布局 xml 文件 catalog_product_view.xml 工作。以下是我的代码和文件名。我可以看到 style.css 和 script.js 工作,它们包含在布局 xml 文件头标记中,我可以说模块工作正常,但没有调用模板。
任何见解都会很有帮助。
catalog_product_view.xml
<?xml version="1.0"?>
<page layout="1column" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<head>
<link src="GBD_GAEcommerce::script.js"/> <!-- this is working -->
<css src="GBD_GAEcommerce::style.css"/> <!-- this is working -->
</head>
<body>
<referenceBlock name="page.main.title">
<block class="GBD\GAEcommerce\Block\ProductInfo" template="GBD_GAEcommerce::product.phtml" name="product.gainfo" after="-"/>
</referenceBlock> <!-- this is not working -->
</body>
</page>
块/ProductInfo.php
<?php
namespace GBD\GAEcommerce\Block;
class ProductInfo extends \Magento\Framework\View\Element\Template
{
protected $_registry;
public function __construct(
\Magento\Backend\Block\Template\Context $context,
\Magento\Framework\Registry $registry,
array $data = []
)
{
$this->_registry = $registry;
parent::__construct($context, $data);
}
public function _prepareLayout()
{
return parent::_prepareLayout();
}
public function getCurrentCategory()
{
return $this->_registry->registry('current_category');
}
public function getCurrentProduct()
{
return $this->_registry->registry('current_product');
}
}
?>
【问题讨论】: