We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 21624
    • 1 Posts
    Title snippet: classActive
    Parameter: docID (The Document ID)
    Default docID: 1

    Snippet Code:

    <?php
    $active='active';
    $inactive='inactive';
    $id=$modx->documentIdentifier;
      
    $link = isset($docID) ? $docID : '1';
    
    if(($link==$id))
    {
    return $active;
    }
    else {
    return $inactive;
    }
    ?>



    Navigation code:

    <nav><ul>
                    <li class="[[classActive]]"><a href="www.thoughtcache.net">home</a></li>
    		<li class="[[classActive? &docID=`2`]]"><a href="#">wiki</a></li>
    		<li class="[[classActive? &docID=`5`]]"><a href="peanuts.html">about</a></li>
    	</ul></nav>



    The snippet merely compares the current document id to the one you set for the link -- if they match, then the class of the listed item is set to ’active’. Otherwise the class is set to ’inactive’. Its working fine for me, I have been testing it this morning on my own site to set a background color to the class=’active’ link.

    Just thought I might let it out there for someone else to try.