Get CMS Page collection by URL Key in Magento 2

You can get specific CMS page collections in Magento 2 by calling interface, Magento\Cms\Api\PageRepositoryInterface.

PageRepositoryInterface is used when you need to fetch a collection of CMS pages or get specific CMS page data.

You need to instantiate PageRepositoryInterface in __construct() method of Class.  If you want to Get All CMS Pages Collection refer to Get All CMS Pages Collection Magento 2

Continue reading “Get CMS Page collection by URL Key in Magento 2”

How to get referer URL in Magento 2.

Magento 2, Get Referer url by calling function getRefererUrl() or getRedirectUrl() from RedirectInterface Object.

Magento core Interface, Magento\Framework\App\Response\RedirectInterface used for fetching Referer URL.

Continue reading “How to get referer URL in Magento 2.”

How to redirect from Observer in Magento 2?

Magento 2, You can redirect to any custom URL from Observer file. When you have created event observer for any specific event and you want to redirect to any URL in a site, You can redirect from observer simply by calling below code,

Create an observer file under app/code/{Packagename}/{Modulename}/YourEventObserver.php

Continue reading “How to redirect from Observer in Magento 2?”