0

I'm currently rewriting a layout file:

<referenceBlock name="checkout.cart.totals>

<!-- some stuff -->
</referenceBlock>

Is it possible to set the block class here?

7
  • Means you want to change existing block class name? – Amit Bera Jun 10 '19 at 14:07
  • Yes, I want the block to use another class. – user11455652 Jun 10 '19 at 14:10
  • You do not change the block class name like a template(.phtml) changes – Amit Bera Jun 10 '19 at 14:10
  • So it is not possible at all ? – user11455652 Jun 10 '19 at 14:11
  • You cannot change block name using layout – Amit Bera Jun 10 '19 at 14:14
1

As of 2.2.* the short answer: No

What you can do instead is to remove and then add new block with your specific class:

<referenceContainer name="content">
    <!-- Remove old block -->
    <referenceBlock name="checkout.cart.totals" remove="true"/>

    <!-- Add new block -->
    <block name="checkout.cart.totals" class="Vendor\Module\Block\Checkout\Cart\Totals">
        <!-- some stuff -->
    </block>
</referenceContainer>

The other way is to extend Vendor Block class for your needs, you can read more about it here: https://devdocs.magento.com/guides/v2.3/extension-dev-guide/module-development.html

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.