I'm trying to change the template of a block to a template defined in my extension.
The layout file "Magento\Checkout\view\frontend\layout\checkout_cart_item_renderers.xml" has this piece of code:
<update handle="checkout_item_price_renderers"/> <body> <referenceBlock name="checkout.cart.item.renderers"> <block class="Magento\Checkout\Block\Cart\Item\Renderer" as="default" template="cart/item/default.phtml"> <block class="Magento\Checkout\Block\Cart\Item\Renderer\Actions" name="checkout.cart.item.renderers.default.actions" as="actions"> <block class="Magento\Checkout\Block\Cart\Item\Renderer\Actions\Edit" name="checkout.cart.item.renderers.default.actions.edit" template="Magento_Checkout::cart/item/renderer/actions/edit.phtml"/> <block class="Magento\Checkout\Block\Cart\Item\Renderer\Actions\Remove" name="checkout.cart.item.renderers.default.actions.remove" template="Magento_Checkout::cart/item/renderer/actions/remove.phtml"/> </block> </block> <block class="Magento\Checkout\Block\Cart\Item\Renderer" as="simple" template="cart/item/default.phtml"> <block class="Magento\Checkout\Block\Cart\Item\Renderer\Actions" name="checkout.cart.item.renderers.simple.actions" as="actions"> <block class="Magento\Checkout\Block\Cart\Item\Renderer\Actions\Edit" name="checkout.cart.item.renderers.simple.actions.edit" template="Magento_Checkout::cart/item/renderer/actions/edit.phtml"/> <block class="Magento\Checkout\Block\Cart\Item\Renderer\Actions\Remove" name="checkout.cart.item.renderers.simple.actions.remove" template="Magento_Checkout::cart/item/renderer/actions/remove.phtml"/> </block> </block> </referenceBlock> </body>
I've copied the default.phtml to my extension and added a column, but how can I overwrite the template that is used?
For now I have this layout file defined in my extension.
<body> <referenceBlock name="checkout.cart.item.renderers"> <block class="Magento\Checkout\Block\Cart\Item\Renderer" as="default" template="ORG_ShoppingCart::default.phtml"/> <block class="Magento\Checkout\Block\Cart\Item\Renderer" as="simple" template="ORG_ShoppingCart::default.phtml"/> </referenceBlock> </body>
But than I get the error: "'The element 'checkout.cart.item.renderers' already has a child with alias 'default''".
Hi @rklerck,
alias name can be anything. Change default to something else in your modle and then try it.
the logic code is :
<body> <referenceBlock name="checkout.cart.item.renderers"> <referenceBlock name="default"> <action method="setTemplate"> <argument name="template" xsi:type="string">ORG_ShoppingCart::default.phtml</argument> </action> </referenceBlock> <referenceBlock name="simple"> <action method="setTemplate"> <argument name="template" xsi:type="string">ORG_ShoppingCart::default.phtml</argument> </action> </referenceBlock> </body>
I have tried this...but no luck
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<body>
<referenceBlock name="checkout.cart.item.renderers">
<referenceBlock name="default">
<action method="setTemplate">
<argument name="template" xsi:type="string">Mymodule_Customshipping::cart/item/default.phtml</argument>
</action>
</referenceBlock>
<referenceBlock name="simple">
<action method="setTemplate">
<argument name="template" xsi:type="string">Mymodule_Customshipping::cart/item/default.phtml</argument>
</action>
</referenceBlock>
</referenceBlock>
</body>
</page>