5

How to change block's template in layout XML? I tried the solution proposed in this thread:

<referenceBlock name="copyright">
    <arguments>
        <argument name="template" xsi:type="string">Vendor_Module::new.phtml</argument>
    </arguments>
</referenceBlock>

but I can't get it to work. I'm not sure if I'm doing it wrong.

If I change it to action method="setTemplate" (just like in other popular answer for this question, e.g. here):

<referenceBlock name="copyright">
    <action method="setTemplate">
        <argument name="template" xsi:type="string">Vendor_Module::new.phtml</argument>
    </action>
</referenceBlock>

all works fine and the template file is correctly changed.

So what is wrong in the first example? I'd like to avoid using action since it is marked as deprecated.

5

To me, the fist syntax is definitely not right, an issue has even been raised regarding it: https://github.com/magento/magento2/issues/3356

The use of the setTemplate action method is still right for now as it has not been refactored yet.

Also as an alternative, you should try:

<referenceBlock name="copyright" template="Vendor_Module::new.phtml" />
| improve this answer | |
  • 1
    Can confirm for Magento 2.2 that <referenceBlock template="..." /> works – Fabian Schmengler Feb 23 '18 at 12:25
2

You have to set new template file using default.xml file,

Set below xml inside your theme default.xml file and remove cache and see changes.

Add new.phtml file inside app/code/Vendor/Module/view/frontend/templates/new.phtml file

 <referenceBlock name="copyright" template="Vendor_Module::new.phtml" />
| improve this answer | |

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.