Converting CMS Page Content or any Custom content to HTML in Magento 2?
in the below example we will show how to convert the content to HTML in Magento2
/**
* @var \Magento\Cms\Model\Template\FilterProvider
*/
protected $_filterProvider;
/**
* @var \Magento\Store\Model\StoreManagerInterface
*/
protected $_storeManager;
/**
* @param \Magento\Cms\Model\Template\FilterProvider $filterProvider
* @param \Magento\Store\Model\StoreManagerInterface $storeManager
*/
public function __construct(
\Magento\Cms\Model\Template\FilterProvider $filterProvider,
\Magento\Store\Model\StoreManagerInterface $storeManager
) {
$this->_filterProvider = $filterProvider;
$this->_storeManager = $storeManager;
}
/**
* Static block $content
*/
public function getHtmlFromContent($content)
{
$storeId = $this->_storeManager->getStore()->getId();
return $this->_filterProvider->getBlockFilter()->setStoreId($storeId)->filter($content);
}
then in your final block you can use this