1 Comment

Magento 2 – load cms page

Magento 2 Load - Block (CMS Static Block in Magento 1 terms)
available sort by not editable

I am attempting to load a CMS Page from my controller. The community here was kind enough to help me with a CMS Static Block – and now I need a pointer in the right direction for a cms Page.

What is the proper syntax to load a CMS Page by identifier or block id and what factory supports this type of loading?

Related Posts

Magento 2 Load - Block (CMS Static Block in Magento 1 terms)
available sort by not editable

1 Comment on this article

  • User November 12, 2016

    Found the solution. Documenting for posterity.

    ...
    use Magento/Cms/Model/PageFactory;
    
    protected $pageFactory;
    
    public function __construct(...,PageFactory $pagefactory,...) {
    ...
    $this->pageFactory = $pageFactory;
    ...
    }
    
    public function loadCMSPage() {
    ...
    $page = $this->pageFactory->create()->load(<PAGE URL OR ID HERE>);
    ...
    }
    

    Reply

Add a comment