I am trying to customize the
product/view/addtocart.phtml template in my extension. I was already able to customize other templates but for this one it just won't work.
I found the template is defined in
among much more XML is this bit:
<block class="Magento\Catalog\Block\Product\View" name="product.info" template="product/view/form.phtml" after="alert.urls"> <container name="product.info.form.content" as="product_info_form_content"> <block class="Magento\Catalog\Block\Product\View" name="product.info.addtocart" as="addtocart" template="product/view/addtocart.phtml"/> </container>
I know the XML which determines what template is loaded for the "product.info.addtocart". Because if I change the template of in this XML to template
It successfully overrides the template with my own. However of course I need to do this from within my module. I already tried many ways but not matter what I try it has no effect...
Among other things I have created a file
and put the following code in it:
<?xml version="1.0"?> <layout xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/layout_generic.xsd"> <referenceBlock name="product.info.addtocart"> <arguments> <argument name="template" xsi:type="array"> <item name="0" xsi:type="string">MyNamespace_MyModule::product/view/addtocart.phtml</item> </argument> </arguments> </referenceBlock> <referenceContainer name="content" remove="true"> </layout>
and it has no effect. Interestingly notice the
<referenceContainer name="content" remove="true">
that should actually blank the page but it does nothing either (if I put the same XML bit in the
catalog_product_view.xml then it effectively blanks the page..).
So I assume the problem is not that my code is not good but rather that my whole layout XML is not being read for some reason... I thought maybe I had a permission problem so just to be sure I chmoded the whole Module directory at 777 but still my layout XML has no effect...
How come I am unable to override anything, why is my
having no effect?? Could it have something to do with the order of loading the modules?
If yes how come I am able to overide other layout XML from the Magento Catalog module from the same module such as
Thanks for your help!!