回声类“;活动的”;如果当前url为Magento


Echo class "active" if current url Magento

我的Magento模板文件中有几个链接。如果用户当前正在查看的页面是其中一个链接,我希望该链接显示CSS类"活动"。我怎样才能做到这一点?

$routeName   =  Mage::app()->getRequest()->getRouteName();
$identifier  =  Mage::getSingleton('cms/page')->getIdentifier();

上述变量$routeName可用于检查当前页面是否为CMS页面。另一个变量$identifier将输出页面标识符。

Magento为每个页面单独分配类获得活动状态的最简单方法是为每个链接分配一个类,然后为特定的主体类和链接类编写一个CSS角色。

     body.page-a a.class-a {
    color:red}
     body.page-b a.class-b {
    color:red}
    <body class="page-b">
    <a class="class-a">page a</a>
    <a class="class-b">page b</a>
</body>

创建一个包含所有链接(或页面)的数组

$urls = array('home.php', 'about.php', 'contact.php');

然后将当前url与数组中的url进行比较:

<li><a href="about.php" <?php if(in_array($current_url, $urls))
 { echo 'class="active"'; } ?>>About Us</a></li>;