I'm trying to change the language switcher(languages.phtml) to a website switcher.

echo count($block->getStores()) 

Returns the number of stores correctly but when I do

echo count($block->getWebsites()) 

it returns zero when I have 3 websites set up. Is this code wrong or is there something that I need to look into?

1 Answer 1


This link can be helpful for you. Haven't tried the code yet but it should be working:-

Magento 2 - How to list websites on frontend

In your block file:-

public function getWebsites() {
    return $this->_storeManager->getWebsites();

And then in your template file, you can check:-


I am assuming you have not used this function in your block file, as it is not mentioned.

P.S:- The link also have a discussion regarding Store switcher in comments, that can be helpful for you too.

  • Hello, thank you very much for the information. I really appreciate it. I didn't know about the block file thing, I will look into this!
    – Mike
    Nov 22, 2017 at 15:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.