Toggle Nav
My Cart 0

How to get current CMS page data in magento 2

How to get current CMS page data in magento 2

How to get current CMS page data in magento 2

The CMS page query returns information about content pages that were developed with the Magento Content Management System (CMS).

To get the id of current CMS page in Magento 2, use the following code snippet.

protected $_page;
public function __construct(
    ...
    \Magento\Cms\Model\Page $page,
    ...
    array $data = []
) {
    parent::__construct($context, $data);
    ...
    $this->_page = $page;
    ...
}
if ($this->_page->getId()) {
    $pageId = $this->_page->getId();
}

There are so many other methods to get CMS page details like title, identifier, content, and content heading. Let's check one by one.

To get the identifier of the current CMS page you can use

$pageIdentifier = $this->_page->getIdentifier();

To get the Page Title :

$pageTitle = $this->_page->getTitle();

To get the Page Content :

$pageContent = $this->_page->getContent();

To get the Page Content Heading:

$pageContentHeading = $this->_page->getContentHeading();
June 18, 2021
Did you like this post?
0
0