We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 3140
    • 2 Posts
    I’m trying to work out how I would pass a variable, based on the page to this script in the head of my content template. I want to set the Active link for the page so the menu highlights correctly. You can see it working on the site at http://ryokan.shapiro.net.au/modx/index.php?id=56

    active:<insert_variable_here>


    Below is the full Script, its for the Accordian.js menu.

    <script type="text/javascript">
        $(document).ready(function() {
            $(function() {
                $(".left-navigation").accordion({
                    autoHeight: false,
                    collapsible: true,
                    active: 0  //set the active link - index starts at 0. To hide all use false.
                });
    
                //highlight main navigation
                $("#navigation div.inner ul li:first-child a").addClass('selected');
    
                //highlight overview link
                $('.left-navigation-container > h3').addClass('ui-state-active');
    
            });
        });
    </script>
    
      • 28042 ☆ A M B ☆
      • 24,524 Posts
      If you are using Wayfinder to generate the HTML for the menu, it will add the classname of your choice to the active menu item. There are two options; one to give a classname to the active item and its parents all the way up to the top-level, or one to give a classname only to the actual active item.

      You can use mini-templates for Wayfinder’s output to have it generate any kind of containers you want; by default it uses nested unordered lists.

      Then the javascript only needs to work with the HTML elements that Wayfinder generated.
        Studying MODX in the desert - http://sottwell.com
        Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
        Join the Slack Community - http://modx.org
        • 34162
        • 1 Posts
        @scottwell

        Hmm... something I try to achieve on http://wemseo.com/testserver/cb22/cb24/homeshow3.html but I can’t wrap my brain around it.
        Mind seeking your pro-assistance in that case?