2

I have one module called Test_A. We can override any layout of Module-theme in Test_A by giving the same name.

Ex. Module-theme/view/frontend/layouts/frontname_controller_action.xml

can be override by creating file

Test_A/view/frontend/layouts/frontname_controller_action.xml.

But how can we override Module-theme/view/frontend/layouts/default.xml in My Module.

Why we have to create custom theme for it?

We can't modify any module's default.xml layout?

10
  • Why do you want override default.xml from theme into your custom module ?
    – PЯINCƎ
    Nov 25, 2019 at 10:55
  • @PЯINCƏ I want to add a block after top links
    – 26vivek
    Nov 25, 2019 at 11:13
  • You want to add custom top links after core top links? Nov 25, 2019 at 11:37
  • @26vivek Add it in default_head_blocks.xml as Magento recommend : app/code/Vendor/Modulename/view/frontend/layout/default_head_blocks.xml
    – PЯINCƎ
    Nov 25, 2019 at 12:25
  • @PЯINCƏ I want to remove top links block also.
    – 26vivek
    Nov 25, 2019 at 13:19

1 Answer 1

0

Create default.xml in your module and add this below code :

app/code/Vendor/Module/view/layout/default.xml

<?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">
    <body>
        <referenceBlock name="header.links">
            <!-- remove core link -->
            <referenceBlock name="my-account-link" remove="true" />
            <!-- Add new link -->
            <block class="Magento\Framework\View\Element\Html\Link" name="custom.link" before="wish-list-link">
                <arguments>
                    <argument name="label" xsi:type="string" translate="false">Custom Link</argument>
                    <argument name="path" xsi:type="string" translate="false">custom-path</argument>
                </arguments>
            </block>
        </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.