We sacrifice by not doing any other technology, so that you get the best of Magento.

We sacrifice by not doing any other technology, so that you get the best of Magento.

If you need lists of websites in template file then follow below steps:

Add one block file(GetWebsiteList.php) in your existing module and paste below code:

<?php 
namespace VendernameModulenameBlock; 
class GetWebsiteList extends MagentoFrameworkViewElementTemplate 
{ 
    public function __construct( 
        MagentoFrameworkViewElementTemplateContext $context, 
        MagentoStoreModelResourceModelWebsiteCollectionFactory $websiteCollectionFactory, 
        array $data = [] ) 
    {
        $this->_websiteCollectionFactory = $websiteCollectionFactory;
        parent::__construct($context, $data);
    }

     /**
     * Retrieve websites collection of system
     *
     * @return Website Collection
     */
    public function getWebsiteLists()
    {
        $collection = $this->_websiteCollectionFactory->create();
        return $collection;
    }
}

Call in the template file,

<?php foreach($block->getWebsiteLists() as $website) {
	echo $website->getCode(); //code of website
	echo $website->getName(); //name of website
	print_r($website->getData());
}
Fill the below form if you have any Magento programming need.

    Recent Articles
    Get a Free Quote

      Let’s initiate a discussion!!