0

How can I move Product.info.media block to my custom created tab on product view page in Magento 2.

My custom tab code is:

<block class="Magento\Catalog\Block\Product\View" name="specs.tab" as="specification" template="Magento_Catalog::product/related-products.phtml" group="detailed_info">
    <arguments>
        <argument translate="true" name="title" xsi:type="string">Specification</argument>
    </arguments>
</block>
0

Edit your catalog_product_view.xml file, and add the following code as a child of the <body> tag :

<move element="product.info.media" destination="specs.tab" as="product.info.media" />

This will move the block into your block, meaning the product.info.media is now a child of your block. Blocks can render their children from their templates. So you will need to add the following code to your template file which according to your code is Magento_Catalog::product/related-products.phtml :

<?= $block->getChildHtml('product.info.media') ?>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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