首页 > 解决方案 > 将字幕添加到类别列表 magento 2

问题描述

对于我的 magento2 商店,我希望在产品标题下方有一个副标题。

现在我用下一个代码为“产品概述”工作:

我将此代码添加到:catalog_product_view.xml

<referenceBlock name="category.product.addto">
    <block class="" name="category.subtitle" template="product/view/subtitle.phtml" />
</referenceBlock>

我创建了一个新subtitle.phtml的,其中包含下一个代码:

<h3><?php /* @escapeNotVerified */ echo $block->getProduct()->getResource()->getAttribute('subtitle1')->getFrontend()->getValue($block->getProduct()); ?></h3>

但我不知道如何让它在类别列表中工作。

有人可以帮助我吗?

更新:

我创建的属性具有正确的设置(在产品列表中使用已启用)

我正在使用的代码是:

<referenceBlock name="product-item-details"> <block class="Magento\Framework\View\Element\Template" name="category.subtitle" template="product/view/subtitle.phtml" /> </referenceBlock>
i placed this code in "catalog_product_view.xml

我没有在网格视图/类别视图中获得我的标题下方的字幕。

我认为参考块中的代码一定有问题,但我不知道问题出在哪里。

谢谢!关于马克

标签: phpxml

解决方案



推荐阅读