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

2 Answers 2

0

Find an answer

<?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;

?>

0

app/code/Ravindra/slider/Block/slider.php

<?php
namespace Ravindra\slider\Block;

use Magento\Framework\View\Element\Template;

class slider extends Template
{

    protected $filterProvider;

    public function __construct(
        Template\Context $context,
        \Magento\Cms\Model\Template\FilterProvider $filterProvider,
        array $data = []
    ) {
        parent::__construct($context, $data);
        $this->filterProvider = $filterProvider;
        $this->_isScopePrivate = true;
    }
    public function getCmsFilterContent($content)
    {
        $filterManager = $this->filterProvider->getPageFilter()->filter($content);

        return $filterManager;
    }
}

app/code/Ravindra/Slider/view/frontend/templates/slider.phtml

<div class="slide_content">
    <?php echo $block->getCmsFilterContent($_slider['content']); ?>
</div>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.