Magento - check if cms page
16,279
The following should give you what you want
//from a block or phtml script
$this->getRequest()->getModuleName()
When this returns the string 'cms', you're on a CMS page.
When Magento's frontend and admin routers can't find a match on your URL, the CMS router takes over. If the CMS router finds a match (based on the CMS pages you've setup), it hands off the request to the cms module and Mage_Cms_IndexController controller.
Author by
Rito
Fullstack Developer since 2007 Things I love: javascript, sass, php, snow-/wakeboarding, dancing, traveling, gaming
Updated on July 16, 2022Comments
-
Rito almost 2 years
i want to check via php if a page is a cms_page in Magento. I need diffrent breadcrumbs for cms pages, so im trying to this with a condition, but i have no idea how to or where to look at. Heres my breadcrumbs.phtml so far.
<?php if(this is a cms page): ?> <p>some content</p> <?php else: ?> <?php if($crumbs && is_array($crumbs)): ?> <div class="breadcrumbs"> <ul> <?php $charsges = 0; ?> <?php foreach($crumbs as $_crumbName=>$_crumbInfo): ?> <?php $charsges = strlen($_crumbInfo['label']) + $charsges; if($charsges > 40){ $chars = 18; if(strlen($_crumbInfo['label']) > $chars){ $_crumbInfo['label'] = substr($_crumbInfo['label'], 0, $chars); $_crumbInfo['label'] = $_crumbInfo['label'].'..'; } } ?> <li class="<?php echo $_crumbName ?>"> <?php if($_crumbInfo['link']): ?> <a href="<?php echo $_crumbInfo['link'] ?>" title="<?php echo $this->htmlEscape($_crumbInfo['title']) ?>"><?php echo $this->htmlEscape($_crumbInfo['label']) ?></a> <?php elseif($_crumbInfo['last']): ?> <strong><?php echo $this->htmlEscape($_crumbInfo['label']) ?></strong> <?php else: ?> <?php echo $this->htmlEscape($_crumbInfo['label']) ?> <?php endif; ?> <?php if(!$_crumbInfo['last']): ?> <span> > </span> <?php endif; ?> </li> <?php endforeach; ?> </ul> </div> <?php endif; ?>
greets rito
-
cmuench almost 9 years
Mage::app()->getRequest()->getRouteName() === 'cms'
-
Ricardo Martins over 8 yearsI would use Mage::app()->getRequest()->getRequestedRouteName() instead, because in Enterprise it returns "enterprise_pagecache" instead "cms" when cache is enabled.