Search code examples
magento2

Override layout xml on child theme doesn't work


I try to override my layout file from my theme in my child theme

I'm on magento 2.2.11 and I want to override my xml file from my theme with a child theme. I try to follow magento doc without success

I have :

app/design/frontend/Myvendor/mytheme/Myvendor_Header/layout/default.xml

And I want override him.

I try with this:

app/design/frontend/Myvendor/mytheme_child/Myvendor_Header/layout/override/theme/Myvendor/mytheme/default.xml

And my xml child doesn't work, I don't have error. It load only my parent xml.

My child theme is defined correctly because my .phtml files override parent file.

Do you have an solution for override my layout parent ?


Solution

  • I found a solution to my problem.

    To start check if the theme is set in physical.

    Go to your database -> table "theme" -> columns "type" must be 0

    If you are testing multiple sites on one domain

    For force a particular website go to index.php and add these lines :

    $params[\Magento\Store\Model\StoreManager::PARAM_RUN_CODE] = "my_website_view";
    $params[\Magento\Store\Model\StoreManager::PARAM_RUN_TYPE] = 'store';
    $bootstrap = \Magento\Framework\App\Bootstrap::create(BP, $params);
    

    Put the child layout in the child theme

    app/design/frontend/Myvendor/mytheme_child/Myvendor_Header/layout/default.xml

    Finally, launch command

    1. rm -rf generated/code/ generated/metadata/* var/page_cache/* var/view_preprocessed/* var/cache/*
    2. php bin/magento cache:flush
    3. php bin/magento setup:upgrade
    4. php bin/magento setup:static-content:deploy -f