4

How to add block near a product image in a product detail page in Magento 2

https://prnt.sc/no8cfd

1

Add below code in \view\frontend\layout\catalog_product_view.xml and clean cache

<?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">
    <referenceContainer name="product.info.media">
        <container name="" htmlTag="div" htmlClass="" before="skip_gallery_after.target">
            <block class="" name="" template="" />
        </container>
    </referenceContainer>
</page>
2

Add below code and change block identifier name

app\design\frontend\YourVendor\YourTheme\Magento_Catalog\layout\catalog_product_view.xml

<referenceContainer name="content">
            <block class="Magento\Cms\Block\Block" name="block-identifier" before="product.info.media">
                <arguments>
                    <argument name="block_id" xsi:type="string">block-identifier</argument>
                </arguments>
            </block>
</referenceContainer>

Clear cache and check..

4
  • i want to add a block in custom module – Divya Sekar May 14 '19 at 5:42
  • via xml or phtml ?? – Mohammad Faizan May 14 '19 at 5:43
  • add a layout in xml – Divya Sekar May 14 '19 at 5:45
  • If you have created custom module, you can use my code as i mention in above answered. just have to use module layout xml file. – Mohammad Faizan May 14 '19 at 5:47

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.