Magento - check if cms page

回眸只為那壹抹淺笑 提交于 2019-12-04 19:33:02

问题


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

greets rito


回答1:


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.



来源:https://stackoverflow.com/questions/3477893/magento-check-if-cms-page

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!