0

Is there any possibility to add ViewModel to the existing block and PHTMl file? I'm trying to add ViewModel to the file below.

sales_email_order_renderers

Code:

<?xml version="1.0"?>
<!--
/**
 * Copyright © Magento, Inc. All rights reserved.
 * See COPYING.txt for license details.
 */
-->
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd" label="Email Creditmemo Items List" design_abstraction="custom">
    <body>
        <referenceBlock name="sales.email.order.renderers">
            <block class="Magento\Sales\Block\Order\Email\Items\Order\DefaultOrder" name="sales.email.order.renderers.default" as="default" template="Test_Module::email/items/order/default.phtml"/>
        </referenceBlock>
    </body>
</page>

Thanks in advance

2 Answers 2

0

Even though its late to answer your question, it may help someone. You can add viewModel like below arguments syntax.

<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd" label="Email Creditmemo Items List" design_abstraction="custom">
    <body>
        <referenceBlock name="sales.email.order.renderers">
            <block class="Magento\Sales\Block\Order\Email\Items\Order\DefaultOrder" name="sales.email.order.renderers.default" as="default" template="Test_Module::email/items/order/default.phtml">
                <arguments>
                    <argument name="view_model" xsi:type="object">Test\Module\ViewModel\Sales\Block\ViewModelClass</argument>
                </arguments>
            </block>
        </referenceBlock>
    </body>
</page>
0

All the XML files will be merged in the end, so we can directly use the block name in the referenceBlock tag and change the template and add the view model for additional functionalities. Find the below sample code.

<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd"
      label="Email Creditmemo Items List" design_abstraction="custom">
<body>
    <referenceBlock name="sales.email.order.renderers.default" template="Test_Module::email/items/order/default.phtml">
        <arguments>
            <argument name="view_model" xsi:type="object">Test\Module\ViewModel\Email\Items\Order\DefaultOrder</argument>
        </arguments>
    </referenceBlock>
</body>
</page>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.