0

I'm trying to show a custom block for each store view / language. Therefore I want to create switch statement like:

$lang = // Get language code or store view code here;
switch ($lang) {

    case 'en':
        // English block
        break;

    case 'nl':
        // Dutch block
        break;

    default:
        // Dutch block
        break;
}

How can I get this? I need it in this file \app\design\frontend\Venustheme\floristy\Ves_Themesettings\templates\header\default.phtml

Rick
  • 463
  • 7
  • 18

1 Answers1

1

Use \Magento\Store\Api\Data\StoreInterface in __construct() of your Block class corresponding to your template file.

Example:

/**@var \Magento\Store\Api\Data\StoreInterface **/
protected $_store;

public function __construct(
\Magento\Store\Api\Data\StoreInterface $store,
  .....
) {
  $this->_store = $store;
} 

public function getLocaleCode()
{
    return $this->_store->getLocaleCode();
}

Call getLocaleCode() function from template file using $block->getLocaleCode() which should return something like en_EN.

amitshree
  • 2,048
  • 2
  • 23
  • 41