Magento - 检查是否为CMS页面

9

我希望通过php检查一个页面是否是Magento中的cms页面。我需要为cms页面提供不同的面包屑,因此我正在尝试使用条件来实现,但我不知道如何或在哪里查看。 以下是我的breadcrumbs.phtml。

<?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>&nbsp;&gt;&nbsp;</span>
        <?php endif; ?>
        </li>
    <?php endforeach; ?>
    </ul>
</div>
<?php endif; ?>

问候 rito

1个回答

30
以下应该会给你想要的东西。
//from a block or phtml script
$this->getRequest()->getModuleName()
当此函数返回字符串“cms”时,您在CMS页面上。 当Magento的前端和管理路由器无法在您的URL上找到匹配项时,CMS路由器接管。如果CMS路由器找到匹配项(基于您设置的CMS页面),它会将请求移交给cms模块和Mage_Cms_IndexController控制器。

4
Mage::app()->getRequest()->getRouteName() === 'cms' - cmuench
1
我会使用Mage::app()->getRequest()->getRequestedRouteName(),因为在Enterprise中启用缓存时,它返回"enterprise_pagecache"而不是"cms"。 - Ricardo Martins

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接