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?

asked Sep 21, 2020 at 10:06

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!

answered Sep 21, 2020 at 10:55
9
  • Did you updated above content in your XML file ? Commented Sep 21, 2020 at 11:24
  • Clear Magento cache once and try Commented Sep 21, 2020 at 11:24
  • Also please check your module is enabled or not? If you've added above files in your module then please verify it once. Commented Sep 21, 2020 at 11:26
  • Let us continue this discussion in chat. Commented Sep 21, 2020 at 11:27
  • Seems fixing that block class issue didn't resolve it - you able to .zip up your plugin and send it over? I'll see if it works - if it doesn't, might be a problem with the theme Commented Sep 21, 2020 at 14:17

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.