【问题标题】:Magento - check if cms pageMagento - 检查cms页面
【发布时间】:2010-08-13 14:37:52
【问题描述】:

我想通过 php 检查页面是否是 Magento 中的 cms_page。我需要用于 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; ?>

向里托打招呼

【问题讨论】:

    标签: php zend-framework magento conditional-statements


    【解决方案1】:

    以下内容应该可以满足您的需求

    //from a block or phtml script
    $this->getRequest()->getModuleName()
    

    当它返回字符串“cms”时,您就进入了 CMS 页面。

    当 Magento 的前端和管理路由器在您的 URL 上找不到匹配项时,CMS 路由器会接管。如果 CMS 路由器找到匹配项(基于您设置的 CMS 页面),它会将请求交给 cms 模块和 Mage_Cms_IndexController 控制器。

    【讨论】:

    • Mage::app()-&gt;getRequest()-&gt;getRouteName() === 'cms'
    • 我会改用 Mage::app()->getRequest()->getRequestedRouteName(),因为在 Enterprise 中,启用缓存时它会返回“enterprise_pagecache”而不是“cms”。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-04-22
    • 1970-01-01
    • 2011-06-28
    • 2011-10-14
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多