Magento 2 – How to Load CMS Page

controllersmagento2

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?

Best Answer

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>);
...
}