Magento 2 - Call phtml in helper

by Shoaib Munir   Last Updated May 21, 2019 06:09 AM

I have found multiple threads related to calling helper function in .phtml.

But I have a case where I need to call phtml file in helper and return HTML.

I have used this code:

//Where $this->_resultPageFactory is the object of \Magento\Framework\View\Result\PageFactory
$resultPage = $this->_resultPageFactory->create();
$html = $resultPage->getLayout()
return $html;

It is working fine, but the problem is, it is effecting other stuff like Product title, Media gallery etc (it is changed after using above code)

So, how can I call .pthml from helper?

Related Questions

Updated December 19, 2016 08:03 AM

Updated October 16, 2017 09:09 AM

Updated December 13, 2017 06:09 AM

Updated January 11, 2019 21:09 PM