How can I know the current page is CMS page from Magento 2 Block class
You can use “\Magento\Framework\App\Request\Http” to retrieve the current request and use it to find out which module.
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$request = $objectManager->get(‘\Magento\Framework\App\Request\Http’);
$checkModule = $request->getModuleName();
if($checkModule == ‘cms’){
echo “cms page”;
}else{
echo “not cms page”;
}
if($checkModule == ‘cms’){
echo “cms page”;
}else{
echo “not cms page”;
}
0 0 votes
Article Rating