2

I have seen in many layout files with different handle in magento2:

like:

          <update handle="editor">
          <update handle="default"/>

and many more

So what is for the handle and where handles are defined?

I have read many blogs and question about handle but not exactly understood functionality of it.

2

Update handle node in layout files includes the layout_file.xml with the handle attribute's value (here in your example editor.xml and default.xml) in the current layout (like the include_once function of PHP) and executed recursively.

For example, there is a file: app/design/frontend/Vendor/default/Magento_Customer/layout/customer_account_edit.xml

And there is a line <update handle="customer_account"/> which will include the file having name customer_account.xml in current layout rendering and execute it recursively.

So the customer_account_edit.xml will also have the css, js and the css selector classes added by the customer_account.xml (in short all layout changes) file.

<?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">
    <update handle="customer_account"/>
    <body>
        <referenceBlock name="custom.page.title">
            <action method="setPageTitle">
                <argument translate="true" name="title" xsi:type="string">Edit Account Information</argument>
            </action>
        </referenceBlock>

        <referenceContainer name="div.sidebar.additional" remove="true"/>

        <move element="customer_edit" destination="custom.account.wrapper" />
    </body>
</page>

customer_account.xml

<?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" layout="2columns-right" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd" label="Customer My Account (All Pages)" design_abstraction="custom">
    <head>
        <css src="Magento_Theme::css/customer/customer-account.css" media="all" order="202" />
        <script src="Magento_Customer::js/customer-general.js" />
    </head>
    <body>
        <attribute name="class" value="account"/>
        <attribute name="class" value="ve-customer-acc"/>
    </body>
</page>

Dev doc reference: Layout instructions > Update handle

|improve this answer|||||

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.