We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 22059
    • 26 Posts
    Hi all,
    I’m a very newbie and start to developp a new snippet for the needs of my template.
    Actualy it is a matter of active css menu ! I just want to alight the active button. For this it seems that I need to check document ID for saying "id=current" or not ...

    My problem:
    I try to use a php string compare function within the snippet which is not working as should be ...

    $CurrentPage_str = "[*id*]";
    
      if strcmp($CurrentPage_str, $LinkPage) == 0  
          $ShowOrNot=" id=\"current\"";
      else
          $ShowOrNot=" ";
    
    $output = $ShowOrNot;
    return $output;


    and My snippel call would be like this:
    <div id="nav">
    <ul>
        <li [[IM_TopMenuNav-Snippet?LinkPage=`1` ]] ><a href="[~1~]">Home</a></li>
        <li [[IM_TopMenuNav-Snippet?LinkPage=`2` ]] ><a href="[~2~]">MenuPage2</a></li>
        <li [[IM_TopMenuNav-Snippet?LinkPage=`3` ]] ><a href="[~3~]">MenuPage3</a></li>
    </ul>
    </div>
    


    If then click on "Home", I would expect to have :
    <li id="current" ><a href="[~1~]">Home</a></li>


    because of LinkPage == "[*id*]" ...

    Any Idea fellow ?

    I hope to have been clear in my not so good english explanations ...

    OHO.
      • 4041
      • 788 Posts
      try this as your snippet code:

      /*
          menu_highlight snippet
      */
      $linkpage = isset($LinkPage) ? $LinkPage : "";
      
      $output ="";
      
      if($linkpage == $modx->documentIdentifier){
        $output .="id=\"current\"";
      }else{
        $output .="";
      }
      
      return $output;
        xforum
        http://frsbuilders.net (under construction) forum for evolution
        • 22059
        • 26 Posts
        Breezer,

        I CAN BREATH NOW !
        This is working like a charme. Thanx my Lord for advice. Really apperciate it ...

        OHO.

          • 22059
          • 26 Posts
          Hi again,

          I was just thinking of thoses who may have the same problem. The subject title isn’t very clear, so may this help if I add some few key words ? /a new Subject label ... ?

          OHO.
            • 33171
            • 3 Posts
            Thanks so much Breezer and oho!

            I got this working in revolution no problem. I just had to change the link code to this [[~1~]] (Revolution’s link tag syntax is different from evo)

            <div id="nav">
            <ul>
                <li [[IM_TopMenuNav-Snippet?LinkPage=`1` ]] ><a href="[[~1~]]">Home</a></li>
                <li [[IM_TopMenuNav-Snippet?LinkPage=`2` ]] ><a href="[[~2~]]">MenuPage2</a></li>
                <li [[IM_TopMenuNav-Snippet?LinkPage=`3` ]] ><a href="[[~3~]]">MenuPage3</a></li>
            </ul>
            </div>



            I was also using id="active" in my css not id="current" so I changed my snippet call to:

            <div id="nav">
            <ul>
                <li><a [[IM_TopMenuNav-Snippet?LinkPage=`1` ]] href="[~1~]">Home</a></li>
                <li><a [[IM_TopMenuNav-Snippet?LinkPage=`2` ]] href="[~2~]">MenuPage2</a></li>
                <li><a [[IM_TopMenuNav-Snippet?LinkPage=`3` ]] href="[~3~]">MenuPage3</a></li>
            </ul>
            </div>
            


            and snippet code to:

            <?php
            /*
                menu_highlight snippet
            */
            $linkpage = isset($LinkPage) ? $LinkPage : "";
            
            $output ="";
            
            if($linkpage == $modx->documentIdentifier){
              $output .="id=\"active\"";
            }else{
              $output .="";
            }
            
            return $output;
            



            FYI: your snippet needs to be named: IM_TopMenuNav-Snippet
            (I struggled with that as I’m new to php)