In this blog I’ll explain how can you parse content like CMS page. That means parsing the content of WYSIYG editor, parsing contents like shown below,
{{media url="wysiwyg/test.jpg"}} {{config path="trans_email/ident_custom2/name"}} {{widget type="Magento\Cms\Block\Widget\Block" template="widget/static_block/default.phtml" block_id="4"}} {{block class="Magento\Framework\View\Element\Template" name="test" template="Magento_Catalog::product/widget/test.phtml"}}
To parse the content like these you need to get the \Magento\Cms\Model\Template\FilterProvider instance and call the getBlockFilter() or getPageFilter() as shown below,
public function __construct( ..... \Magento\Cms\Model\Template\FilterProvider $filterProvider, ..... ) { ..... $this->filterProvider = $filterProvider; ..... } public function getCMSContent() { ..... $parsedContent = $this->filterProvider->getPageFilter()->filter($content); //$content is the content that you want to parse return $parsedContent; }
Thanks for reading the blog.
Feel free to comment if you face any issue.
Be the first to comment.