We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 10909
    • 32 Posts
    OK so here is my chunk that I have for my menu...

    <php?
    if ($PHP_SELF != 'url1')
    { $page1 = 'none'; } else { $page1 = 'active'; }
    if ($PHP_SELF != 'url2')
    { $page2 = 'none'; } else { $page2 = 'active'; }
    if ($PHP_SELF != 'url3')
    { $page3 = 'none'; } else { $page3 = 'active'; }
    if ($PHP_SELF != 'url4')
    { $page4 = 'none'; } else { $page4 = 'active'; }
    if ($PHP_SELF != 'url5')
    { $page5 = 'none'; } else { $page5 = 'active'; }
    ?>
    
    <li>
       <a href="url1" class="<?echo $page1;?>">
          <span>1</span>
       </a>
    </li>
    <li>
       <a href="url2" class="<?echo $page2;?>">
          <span> 2</span>
       </a>
    </li>
    <li>
       <a href="url3"  class="<?echo $page3;?>">
          <span> 3</span>
       </a>
    </li>
    <li>
       <a href="url4"  class="<?echo $page4;?>">
          <span> 4</span>
       </a>
    </li>
    <li>
       <a href="url5"  class="<?echo $page5;?>">
          <span> 5</span>
       </a>
    </li>
    


    Now ive ported this in from a template that ive made, but it wont work?

    Can any one please provide me with a working solution to set an active li based on page name? Ta!

      • 16278
      • 928 Posts
      Evo or Revo? Either way, you can’t include PHP directly in chunks, you put it in a snippet. See BobRay’s overview for an outline of what’s used for what in MODX.

      If you’re using Evolution, the well established Wayfinder snippet is a pretty painless way of creating menus (with built-in attaching of an "active" class to the current page). You can also use Ditto to make menus, with a different template chunk for the current page.

      I believe Wayfinder is also available for MODX Revolution.

      smiley KP
        • 10909
        • 32 Posts
        Using Revo.

        Oh... No php in chunks at all? That might be why! Ill have a little look at this way finder then... If i can incorporate it with my current theme then its worth a shot smiley
          • 10909
          • 32 Posts
          Upon looking (unless I’ve gotten the complete wrong end of the stick!) way finder isnt what Im after, its just over complicating it in my opinion...

          Just want a simple menu which allows for an active class to be found. Nothing more!
            • 10909
            • 32 Posts
            All done, for those that want to know make this as a snippet and call in whatever place you want. (Obviously changing the URLs to suit)

            Enjoy!

            <?php
            
            if ($_SERVER["REQUEST_URI"] != '/modx/')
            { $page1 = 'none'; } else { $page1 = 'active'; }
            if ($_SERVER["REQUEST_URI"] != '/modx/index.php?id=4')
            { $page2 = 'none'; } else { $page2 = 'active'; }
            if ($_SERVER["REQUEST_URI"] != '/modx/index.php?id=6')
            { $page3 = 'none'; } else { $page3 = 'active'; }
            if ($_SERVER["REQUEST_URI"] != '/modx/index.php?id=11')
            { $page4 = 'none'; } else { $page4 = 'active'; }
            if ($_SERVER["REQUEST_URI"] != '/modx/index.php?id=5')
            { $page5 = 'none'; } else { $page5 = 'active'; }
            $menu = '
            <li>
               <a href="http://test.glcreations.net/modx/" class="'.$page1.'">
                  <span>Home Page</span>
               </a>
            </li>
            <li>
               <a href="http://test.glcreations.net/modx/index.php?id=4" class="'.$page2.'">
                  <span> Text Layout</span>
               </a>
            </li>
            <li>
               <a href="http://test.glcreations.net/modx/index.php?id=6"  class="'.$page3.'">
                  <span> Portfolio Layout</span>
               </a>
            </li>
            <li>
               <a href="http://test.glcreations.net/modx/index.php?id=11"  class="'.$page4.'">
                  <span> Search Layout</span>
               </a>
            </li>
            <li>
               <a href="http://test.glcreations.net/modx/index.php?id=5"  class="'.$page5.'">
                  <span> Contact Us Layout</span>
               </a>
            </li>';
            echo $menu;
              • 18373 ☆ A M B ☆
              • 3,141 Posts
              Hiya,

              Welcome to MODX smiley

              I would just do this:

              [[Wayfinder? &startId=`0` &hereClass=`active` &rowTpl=`chunkName`]]

              chunkName chunk:
              <li>
                <a href="[[+wf.link]]"[[+wf.classes]]>
                  <span>[[+wf.title]]</span>
                </a>
              </li>


              This will fetch all the resources in the site tree that are set to show in the menu, will add the class "active" to the current menu items link (through the [[+wf.classes]] placeholder in your chunk) and the best thing: when your links change, this will still work.

              Now you tell me what’s easier, lol. tongue

              (The above is untested, so if it doesn’t work out of the box please check my spelling and the placeholder names)
                Mark Hamstra • Developer spending his days working on Premium Extras and a MODX Site Dashboard with the ability to remotely upgrade MODX and extras to make the MODX world a little better.

                Tweet me @mark_hamstra, check my infrequent blog at markhamstra.com, my slightly more frequent ramblings at MODX.today or see code at Github.
                • 10909
                • 32 Posts
                Cheers for the suggestion, however I dont want way finder to pull anything, I want just a simple list of menu items that I choose, regardless of folder structure.

                My solution is perfect for my needs smiley
                  • 36805
                  • 354 Posts
                  Quote from: Mark at Feb 24, 2011, 07:15 AM

                  [..] please check my spelling and the placeholder names [..]
                  This
                  <span>[[+wf.link]]</span>

                  Should be
                  <span>[[+wf.title]]</span>

                  Otherwise it looks 100% correct.

                  @ gl creations : Welcome to MODx! As pointed out before : I recommend you start using Wayfinder. It will automate so much, making your life easier and pages load faster. With hardcoded solutions you miss the biggest advantages of using a cms.
                    • 18373 ☆ A M B ☆
                    • 3,141 Posts
                    Quote from: glcreations at Feb 24, 2011, 07:33 AM

                    Cheers for the suggestion, however I dont want way finder to pull anything, I want just a simple list of menu items that I choose, regardless of folder structure.

                    My solution is perfect for my needs smiley

                    Ah, okay. I must have missed that part then tongue

                    Thanks MrDutchy, edited by post :p
                      Mark Hamstra • Developer spending his days working on Premium Extras and a MODX Site Dashboard with the ability to remotely upgrade MODX and extras to make the MODX world a little better.

                      Tweet me @mark_hamstra, check my infrequent blog at markhamstra.com, my slightly more frequent ramblings at MODX.today or see code at Github.