You can replace this code
Controller
resultPageFactory = $pageFactory; $this->_coreRegistry = $coreRegistry; $this->resultJsonFactory = $resultJsonFactory; parent::__construct($context); } public function execute() { $searchWord = $this->getRequest()->getParam('search'); if ($this->_coreRegistry->registry('search_word')) { $this->_coreRegistry->unregister('search_word'); } // set value to _coreRegistry variable search_word $this->_coreRegistry->register('search_word', $searchWord); $resultPage = $this->resultPageFactory->create(); $result = $this->resultJsonFactory->create(); $block = $resultPage->getLayout() ->createBlock('Vendor\SearchStores\Block\ShowResult') ->setTemplate('Vendor_SearchStores::results_modal.phtml') ->toHtml(); $result->setData(['output' => $block]); return $result; } }Search.php
Block
_coreRegistry = $coreRegistry; parent::__construct($context); } public function getSearchWord() { $searchWord = ''; if ($this->registry->registry('search_word')) { $searchWord = $this->registry->registry('search_word'); } //HERE IS WHERE I WANT TO GET THE DATA FROM THE CONTROLLER return $searchWord; } }ShowResult.php
After making the above changes in your Controller and Block file, you can get a search word in your template file.
Hope this will help you!