I have to check which is the current store view. In order to do that I was using the Object Manager to get the store code like this:
$storeCode = \Magento\Framework\App\ObjectManager::getInstance()
->get(\Magento\Store\Model\StoreManagerInterface::class)
->getStore()
->getCode();
if ($storeCode === "en") {
...
};
if ($storeCode === "it") {
...
};
but doing this way in no more recommended, instead I should use the dependency injection technique...
how should I use it?
app/design/frontend/MyTheme/MyDefault/Magento_Catalog/templates/my-template.phtml
$block->getStoreCode();
in your phtml fileBlock/Siteinfo.php
and correct accordingly the namespace path. Then in my template fileMagento_Theme/templates/my-template.phtml
I addedecho $block->getStoreCode();
but it didn't work.