cancel
Showing results for 
Search instead for 
Did you mean: 

Convert cms page content to html interpretation Magento 2

SOLVED
Regular Visitor

Convert cms page content to html interpretation Magento 2

in my root.phtml, I can call for cms page content with :

<?php echo $layoutContent; ?>

but I wanted to use $cmsPage->getContent() instead :

<?php
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();$cmsPage = $objectManager->get('\Magento\Cms\Model\Page');echo $cmsPage->getContent();
?>

I get this for result which is correct but not converting to html interpretation :

{{block class="Magento\Framework\View\Element\Template" template="Magento_Theme::cms/home.phtml"}}

Do you know if I could get it work ? ( toHtml() function return error )

Thanks

1 REPLY
Highlighted
Moderator
Magento
E-Commerce

Re: Convert cms page content to html interpretation Magento 2

You need to do filter content to get proper output for content of Block/Page to custom file,

 

<?php
	$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
	$cmsPage = $objectManager->get('\Magento\Cms\Model\Page');
	$content = $cmsPage->getContent();
	$filterManager = $objectManager->get('Magento\Cms\Model\Template\FilterProvider')->getPageFilter()->filter($content);
	echo $filterManager;
?>

If issue solved, Click Kudos/Accept as solutions.