Echo类“活跃”如果当前url Magento

时间:2012-08-06 04:57:54

标签: php css magento

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

3 个答案:

答案 0 :(得分:0)

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

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

答案 1 :(得分:0)

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

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

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

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

答案 2 :(得分:0)

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>
相关问题