Magento – How to reference a block that only has an alias, and no name in Magento 2

layoutmagento2overrides

I am attempting to modify some arguments for a block that is defined in module-sales/view/adminhtml/layout/sales_order_view.xml on line 41.

<block class="Magento\Sales\Block\Adminhtml\Order\View\Items\Renderer\DefaultRenderer" as="default" template="order/view/items/renderer/default.phtml">

The problem, is that the block is not defined with a name, it only has an alias, so I am unable to use something like <referenceBlock name="default"/> to modify it.

I need to modify the "columns" argument inside this block.
Is there any other way to reference this block, or am I pretty much out of luck?

Best Answer

You have to just override using below way,

app/design/frontend/{Vendor}/{themename}/Magento_Sales/layout/sales_order_view.xml file

<?xml version="1.0"?>
<!--
/**
 * Copyright © 2016 Magento. 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">
    <body>
        <referenceContainer name="page.main.title">
            <block class="Magento\Sales\Block\Order\Info" name="order.status" template="order/order_status.phtml"/>
            <block class="Magento\Sales\Block\Order\Info" name="order.date" template="order/order_date.phtml"/>
            <container name="order.actions.container" htmlTag="div" htmlClass="actions-toolbar order-actions-toolbar">
                <block class="Magento\Sales\Block\Order\Info\Buttons" as="buttons" name="sales.order.info.buttons" cacheable="false"/>
            </container>
        </referenceContainer>
        <referenceContainer name="sales.order.info.buttons">
            <block class="Magento\Sales\Block\Order\Info\Buttons\Rss" as="buttons.rss" name="sales.order.info.buttons.rss" cacheable="false"/>
        </referenceContainer>
        <referenceContainer name="content">
            <block class="Magento\Sales\Block\Order\View" name="order.comments" template="order/order_comments.phtml" before="sales.order.info.links"/>
            <block class="Magento\Sales\Block\Order\View" name="sales.order.view" cacheable="false" after="sales.order.info.links">
                <block class="Magento\Sales\Block\Order\Items" name="order_items" template="order/items.phtml">
                    <block class="Magento\Framework\View\Element\RendererList" name="sales.order.items.renderers" as="renderer.list"/>
                    <block class="Magento\Sales\Block\Order\Totals" name="order_totals" template="order/totals.phtml">
                        <arguments>
                            <argument name="label_properties" xsi:type="string">colspan="2" class="mark"</argument>
                            <argument name="value_properties" xsi:type="string">class="amount"</argument>
                        </arguments>
                        <block class="Magento\Tax\Block\Sales\Order\Tax" name="tax" template="order/tax.phtml"/>
                    </block>
                </block>
            </block>
            <block class="Magento\Sales\Block\Order\Info" as="info" name="sales.order.info" after="sales.order.view"/>
        </referenceContainer>
        <block class="Magento\Framework\View\Element\Template" name="additional.product.info" template="Magento_Theme::template.phtml"/>
    </body>
</page>

You can change colspan in above file.

Related Topic