0

I have a relatively straightforward module in Magento 2 for adding some extra functionality to the addto area on the product view page.

I wanted to append my own custom block after the product.info.addto block via a layout file, like so:

app/code/VENDOR/MODULE/view/frontend/layout/catalog_product_view.xml

<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
    <body>
        <referenceBlock name="product.info.options.wrapper.bottom">
            <block
                class="VENDOR\MODULE\Block\Product"
                name="product.info.anyname"
                template="VENDOR_MODULE::test.phtml"
                after="product.info.addtocart" />
        </referenceBlock>
    </body>
</page>

with my template test.phtml file being a simple echo for now:

app/code/VENDOR/MODULE/view/frontend/templates/test.phtml

<?php echo 'LA TREY: '; ?>

after enabling module, and running the di:upgrade, compile and cache clear php bin/magento commands, I go to my catalog product view page and no change. My "La Trey" isn't there.

So I thought I could win by copying the layout/catalog_product/view.xml file to the theme's Magento_Catalog folder - but again, after running the commands - nothing.

How do I get my block to show after the addto container on the catalog product view page?

1 Answer 1

1

Update your XML file content with below code.

app/code/VENDOR/MODULE/view/frontend/layout/catalog_product_view.xml

<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
    <body>
        <referenceContainer name="content">
            <referenceBlock name="product.info.options.wrapper.bottom">
                <block
                    class="VENDOR\MODULE\Block\Product"
                    name="product.info.anyname"
                    template="VENDOR_MODULE::test.phtml"
                    after="product.info.addtocart" />
            </referenceBlock>
        </referenceContainer>
    </body>
</page>

After updating this please run below command once..

php bin/magento cache:flush

Output

enter image description here

Hope this will work!

10

Your Answer

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

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