cancel
Showing results for 
Search instead for 
Did you mean: 

Convert cms page content to html interpretation Magento 2

SOLVED

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 ACCEPTED SOLUTION

Accepted Solutions

Re: Convert cms page content to html interpretation Magento 2

Check full details of the answer with Constructor dependency injection, filter CMS Page(Block) content in template file using 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.

If Issue Solved, Click Kudos/Accept As solutions. Get Magento insight from
Magento 2 Blogs/Tutorial

View solution in original post

3 REPLIES 3

Re: Convert cms page content to html interpretation Magento 2

Check full details of the answer with Constructor dependency injection, filter CMS Page(Block) content in template file using 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.

If Issue Solved, Click Kudos/Accept As solutions. Get Magento insight from
Magento 2 Blogs/Tutorial

Re: Convert cms page content to html interpretation Magento 2

Hey! im trying to do that and im having an issue when i put a widget of a static block like that:

Error filtering template: Invalid template file: 'widget/static_block/default.phtml' in module: 'Magento_Cms' block's name: 'widget\\block_1'

Re: Convert cms page content to html interpretation Magento 2

Hi Ilanvisitu,

 

I am also facing widget statick block filtering issue. Did you get any solution for this?