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()); }