Magento – Change block’s template in layout XML

actionlayoutmagento2template

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.

Best Answer

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" />