To get the id of current CMS page in Magento 2, use the following code snippet.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | 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. Lets check one by one.
To get the identifier of the current CMS page you can use
1 | $pageIdentifier = $this->_page->getIdentifier(); |
To get the Page Title :
1 | $pageTitle = $this->_page->getTitle(); |
To get the Page Content :
1 | $pageContent = $this->_page->getContent(); |
To get the Page Content Heading:
1 | $pageContentHeading = $this->_page->getContentHeading(); |
Thats it.
Write an article about ecommerce that help people to grow their ecommerce business. You’ll find best ecommerce guide, news, tips & more!
April 30, 2020 at 4:26 pm
Great article. I learn new information from your article, you are doing a great job. Keep it up!