2

Suppose that I want to edit the file

vendor/magento/module-theme/view/frontend/layout/default.xml

Do I edit the file directly?

It seems not a best practice to me.

Or is there anyway I can extend the file to override the content.

  • There are several ways to do this. Is your intention to build a custom module which will contain your override or is this part of a theme you are building? – Shawn Abramson Jan 8 '18 at 4:54
1

You can use the following to override the layout file. For Example, vendor/magento/module-theme/view/frontend/layout/default.xml

<vendor_theme_dir>
|__/<vendor_theme>
  |__/Magento_Theme
    |__/view
      |__/frontend
         |__/layout
            |__/default.xml

So you just need to override a file under your theme folder.

| improve this answer | |
  • what is theme_dir and vendor_theme in this case – eulercode Jan 8 '18 at 6:15
  • If you see in app/design/frontend/Magento/Luma - This one is default theme where as if you have any theme installed at that time path will be app/design/frontend/<theme_dir>/<vendor_theme> – Salma Saiyad Jan 8 '18 at 6:24
  • I have only app/design/frontend/Magento and there is no additional folder or file inside it. So i add Luma/Magento_Theme/view/frontend/layout/default.xml inside it am i right? – eulercode Jan 8 '18 at 6:29
  • Yes. Please add same as defined – Salma Saiyad Jan 8 '18 at 7:21
0

You can do the following things. Create new theme and override this layout in theme. Check luma theme, how to override any xml. And do the same. Check official documentation

| improve this answer | |
0

To add an overriding theme file (to override a parent theme layout):

<theme_dir>
  |__/<Namespace_Module>
    |__/layout
      |__/override
         |__/theme
            |__/<Parent_Vendor>
               |__/<parent_theme>
                  |--<layout1>.xml
                  |--<layout2>.xml

Reference: http://devdocs.magento.com/guides/v2.2/frontend-dev-guide/layouts/layout-override.html

| improve this answer | |
  • what is theme_dir, namespace_module, parent_vendor and parent_theme in this case? – eulercode Jan 8 '18 at 6:12
0

Firstly you must create a local theme, for do that you have to create the blow structure

app
---->desing
-------->frontend
------------>Vendor
---------------->default

In this folder you create 2 files

registration.php

<?php
\Magento\Framework\Component\ComponentRegistrar::register(
    \Magento\Framework\Component\ComponentRegistrar::THEME,
    'frontend/Vendor/default',
    __DIR__
);

theme.xml

<theme xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Config/etc/theme.xsd">
    <title>Vendor Theme</title>
</theme>

And finaly you have to create a below structure

Magento_Theme
---->layout
-------->default.xml
| 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.