-1
<?php $currentUrl = Mage::helper('core/url')->getCurrentUrl(); // get current url 
<?php $url = $category->getURL(); ?> 
<li class="<?php if ($currentUrl == $url) {echo 'active';} else{echo '';} ?> dropdown megamenu-fw "></li>

I'm trying to make a condition in li tag on class if the current url equal to current li url then add the class active but it is not working.

Afzal Khan
  • 125
  • 2
  • 14
  • 1
    _but it is not working._ What does that mean? What errors do you see? – B001ᛦ Mar 03 '17 at 10:47
  • the above condition is not working that's my mean – Afzal Khan Mar 03 '17 at 10:48
  • it is not adding the class by this code – Afzal Khan Mar 03 '17 at 10:48
  • First of all there is a missing closing ?> tag in the first line. Second, you should make your first two lines look like: `getCurrentUrl(); // get current url $url = $category->getURL(); ?>` . Third, I would do a `var_dump($currentUrl.'--------'.$url);die;` to check what is inside the variables. – Alex Odenthal Mar 03 '17 at 13:20

2 Answers2

0

You can try this.

If below code not working then you can check first variable value of $currentUrl and $url.

<?php $currentUrl = Mage::helper('core/url')->getCurrentUrl(); // get current url 
<?php $url = $category->getURL(); ?>
<?php if ($currentUrl == $url) {echo '<li class="active dropdown megamenu-fw "></li>';} else { echo '<li class="dropdown megamenu-fw"></li>';} ?> 
Pravin Vavadiya
  • 3,195
  • 1
  • 17
  • 34
-1

Is the URL right? Can the if-statement be true? may you can try to get the URL other way:

$actual_link = "http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";

By the way (may not the real problem):
Your line 1 will send error: You open php in line 1 <?php but didnt closed it, than in line 2 you open php again line2: <?php ... ?>

Kevin Liss
  • 136
  • 1
  • 3
  • 15