We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 15871
    • 105 Posts
    Here’s what I need to do:

    I have a section with many sub pages underneath it. Those pages are Case Studies, but they are underneath their categorized folders under "Services." I have a Case Studies page that pulls that content via Wayfinder. What I need to be able to do is that if a user selects a Case Study from the "Case Studies" page, I need to display a "Back to Case Studies" button on the actual Case Study. In addition, I need the Case Study page to display a "Back to Services" if they clicked on the link from the Services page.

    Is this possible?
      • 15871
      • 105 Posts
      WOOOHOOO!

      I felt inspired so I did some more sniffing, and I actually wrote my own snippet to do what I needed here! Now this is a big deal because I’m a designer by trade, but I really dig me some coding smiley

      If anyone is interested: here is the code:

      Just make a new snippet called "swapChunkonReferer" and paste this into it:

      <?php
      // swapChunkonReferer v 0.1
      // Snippet by killorbytes
      // 3/4/07
      
      //chunkOne is the Chunk to be displayed of the string search of the referer is true
      //chunkTwo is the Chunk to display if the string search does not find a match
      //refererID is the search string to match against the referer
      
      /* Example Call
      
      [!swapChunkonReferer? &chunkOne=`nameofFirstChunk` &chunkTwo=`nameofSecondChunk` &refererID=`referingDocumentAlias`!]
      
      */
      
      $chunkOne = isset($chunkOne) ? $chunkOne : 'back2caseStudies'; //Set name or use default
      $chunkTwo = isset($chunkTwo) ? $chunkTwo : 'destinationChunk'; //Set name or use default
      $refererID = isset($refererID) ? $refererID : 'case-studies'; //Set name or use default
      $referer = $_SERVER['HTTP_REFERER'];
      
      if(stristr($referer,$refererID)) {
      echo '{{' . $chunkOne . '}}';
      } else {
      echo '{{' . $chunkTwo . '}}';
      }
      ?>

        • 28042 ☆ A M B ☆
        • 24,524 Posts
        Welcome to the community! The power! The control! The head rush on success! The headache after spending two days fighting it and finally discovering a forgotten semicolon! grin grin
          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
          • 15871
          • 105 Posts
          grin
          LOL, I actually threw my hands up in the air in victory when it worked! I couldn’t wait to post it, I felt empowered finally giving back. MODx rocks.

          It is now officially 2am. Goodnight everybody!