0

Is this possible to load the cms page/ category inside custom phtml file, if it is possible how we can load cms page/ category inside custom phtml file.

Thanks.

3

1 Answer 1

0

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()

4
  • It's not very professional copy someone else answer from comment specified above as own answer Jun 21 at 15:44
  • Hi @Gohil Rajesh, what is "barnd_list", "identifier" here, we dont have any identifier for the page!
    – Mani
    Jun 22 at 3:47
  • @Mani every page has must be unique identifier. it means url key of your page Jun 22 at 8:28
  • @VictorTihonchuk I am just trying to help here. I believe instead of adding link its better to post answer. I can clarify their doubts too Jun 22 at 8:30

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.