Magento2 development

Here We will know, whether the current page is a CMS page or category view page or product view page or Homepage  in Magento 2

so the first step, to check current page is write the following script in the .phtml file, where you need to identify which page is this?


$objectManager = \Magento\Framework\App\ObjectManager::getInstance();

$request = $objectManager->get('Magento\Framework\App\Action\Context')->getRequest();

Now you identify your current page by following code

if ($request->getFullActionName() == 'catalog_product_view') {
//you are on the product page
}
if ($request->getFullActionName() == 'catalog_category_view') {
//you are on the category page
}
if ($request->getFullActionName() == 'cms_index_index') {
//you are on the home page
}
if ($request->getFullActionName() == 'cms_page_view') {
//you are on the cms page
}

That’s how you can identify current page in Magento 2
I hope it helps you.

In case that you have any queries or questions in above steps , You can do comment below!

Leave a Reply