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?

  • Why do you want override default.xml from theme into your custom module ? – PЯINCƏ Nov 25 '19 at 10:55
  • @PЯINCƏ I want to add a block after top links – 26vivek Nov 25 '19 at 11:13
  • You want to add custom top links after core top links? – Rohan Hapani Nov 25 '19 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 '19 at 12:25
  • @PЯINCƏ I want to remove top links block also. – 26vivek Nov 25 '19 at 13:19
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>
| 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.