4

I have created one CMS page brand and I want to call brand CMS page in phtml file. So how can I call the CMS page?

I got following code but it's not working.

$cmsPage = Mage::getModel('cms/page')->load('Brand List','brand_list');
echo $cmsPage->getContent();
3

Your phtml is rendered by a block class.
You need to add this in your block class.

protected $pageFactory;
protected $brandPage;
public function __construct(
    ....
    \Magento\Cms\Model\PageFactory $pageFactory,
    ....
){
    ....
    $this->pageFactory = $pageFactory;
    ....
}

public function getBrandsPageContent()
{
    if (is_null($this->brandPage)) {
        $this->brandPage = $this->pageFactory->create();
        $this->brandPage->load('brand_list', 'identifier');
    }
    return $this->brandPage->getContent();
}

then in your phtml you just call echo $this->getBrandsPageContent()

2

Try below code for solution.

$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$page = $objectManager->get('\Magento\Cms\Model\Page')->load('brand_list');
echo $objectManager->get('\Magento\Cms\Model\Template\FilterProvider')->getBlockFilter()->filter($page->getContent());
  • Please don't use object manager. It is not coding standard. – Rama Chandran M Jun 9 '17 at 9:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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