I am not sure di.xml
. store specifictarget.
But i am 100% sure that you cannot make default.xml
store specific.
If you want store layout files and where you want to write store specific layout code and want to override other existing layout like default.xml
.
At magento2, layout file name is equal to hanlde name
Then you need to create custom extension on this extension we will create**store specific handler
like** store_default,store_us
etc,
where pattern is store_{YourStore_code}
.
On observer on eventlayout_load_before
- then add your event at observer
- using below code
$layout->getUpdate()->addHandle('store_'.$Storecode);
So, you create layout files like
- store_default.xml
- store_us.xml
At app/design/frontend/{Themevendorname}/{Themename}/layout/{Vendorname}_{Modulename}/layout
This module should consist of below files:
app/code/app/code/{vendorname}/{Modulename}/registration.php
app/code/{vendorname}/{Modulename}/composer.json
app/code/{vendorname}/{Modulename}/etc/module.xml
Define event at
app/code/{vendorname}/{Modulename}/etc/events.xml
code:
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Event/etc/events.xsd">
<event name="layout_load_before">
<observer name="add_Store_layout" instance="{vendorname}\{Modulename}\Observer\addStoreLayout" />
</event>
</config>
Define observer which create store_{YourStore_code}
pattern handle
app/code/{vendorname}/{Modulename}/Observer/addStoreLayout.php
code:
<?php
namespace {vendorname}\{Modulename}\Observer;
use Magento\Framework\Event\ObserverInterface;
class addStoreLayout implements ObserverInterface
{
protected $storeManager;
/**
* addStoreLayout constructor.
* @param \Magento\Store\Model\StoreManagerInterface $storeManager
*/
public function __construct(
\Magento\Store\Model\StoreManagerInterface $storeManager
)
{
$this->storeManager = $storeManager;
}
public function execute(\Magento\Framework\Event\Observer $observer)
{
//['full_action_name' => $this->request->getFullActionName(), 'layout' => $this->layout]
$layout = $observer->getLayout();
$layout->getUpdate()->addHandle('store_'.$this->storeManager->getStore()->getCode());
}
}
At header.phtml
add this code , and you will see you handler
echo "<pre>";
var_dump($block->getLayout()->getUpdate()->getHandles());