【问题标题】:Magento v2 Template file not called from layout file未从布局文件调用 Magento v2 模板文件
【发布时间】:2019-07-28 04:58:40
【问题描述】:

我正在尝试从自定义模块在产品页面中添加一个静态块部分,但无法正常工作。 product.phtml 模板文件调用无法从布局 xml 文件 catalog_product_view.xml 工作。以下是我的代码和文件名。我可以看到 style.cssscript.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');
}    

}
?>

【问题讨论】:

    标签: php magento magento2


    【解决方案1】:

    我尝试使用你的代码它正在工作请检查模板路径。

    插件路径。 GBD/GAEcommerce/view/frontend/templates/product.phtml

    用于设计文件夹路径 GBD_GAEcommerce/templates/product.phtml

    【讨论】:

    • 您能否详细说明您的答案。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-01-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多