1

I'm using magento 2.1.3 and I want to display related products under product_view. Product view is using 1 column template.

I've added successfully related products to some products. I've reindexed after adding related to products. I've cleaned cache after each change of code.

In

/vendor/magento/module-catalog/view/frontend/layout/catalog_product_view.xml

The related products block is placed in referenceContainer name="content.aside" which is not present in my product view as it is one column.

I've overridden this layout in

/app/design/frontend/myCompany/myTheme/Magento_Catalog/layout/catalog_product_view.xml

and every change is working except related products block.

I tried to move it like this

<move element="catalog.product.related" destination="content" after="product.info.main" />

I used several different destinations, even without using after/before, but related products block is not appearing anywhere.

I tried also to call it

<block class="Magento\Catalog\Block\Product\ProductList\Related" name="catalog.product.related" type="related" template="Magento_Catalog::product/list/items.phtml">
    <arguments>
        <argument name="type" xsi:type="string">related</argument>
    </arguments>
</block>

I tried even using and not using type="related" in this last way of calling, but even with or without the 'type' the block is not appearing.

Does somebody have any idea?

2 Answers 2

0

Try this:

<move element="catalog.product.related" destination="product.info.main" after="-" />

Change you XML file path from

/app/design/frontend/myCompany/myTheme/Magento_Catalog/templates/catalog_product_view.xml

To

/app/design/frontend/myCompany/myTheme/Magento_Catalog/layout/catalog_product_view.xml

3
  • I tried it before, but I tried it again now and it is not working.
    – Alex
    May 26, 2017 at 13:19
  • change path, look updated answer May 26, 2017 at 13:28
  • Actually it is in layout folder, it was a typo when copying. I edit it in the question to avoid future misunderstandings. I'm sorry for the typo.
    – Alex
    May 26, 2017 at 13:48
0

Call this Function

$block->getLayout()->createBlock('Magento\Catalog\Block\Product\ProductList\Related')
                    ->setTemplate("Magento_Catalog::product/list/items.phtml")
                    ->setData('type', 'related')
                    ->toHtml();

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.