We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 14214
    • 299 Posts
    Good morning,

    I have a MODx site that recently launched and am running a separate shopping website to avoid the hassle of shopping cart maintenance. To link the site I want to enable a visior on my MODx site to easily locate a product on my shopping site through passing a search string to the shopping website.

    To complete this I would like to create dynamic links based on the page title. The link would format like this: http://shop.mysite.com/search?query=keyword1+keyword2

    What is the easiest way for me (a newbie) to create the link using the page title and replacing spaces with a plus sign? Any input is well appreciated!

    Thanks,

    Jisaac
    • <a href="shop.mysite.com/search?query=[[SearchString]]">blah</a>

      SearchString snippet:
      $string = $modx->documentObject['pagetitle'];
      $string = str_replace(' ', '+', $string);
      return $string;
      
        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
        • 14214
        • 299 Posts
        Susan,

        You’re pretty much amazing! Wasn’t expecting someone to hand me the answer so thorough/complete. Thank you very much!

        Jisaac
          • 14214
          • 299 Posts
          And then to remove a few other random characters I have in my titles I wrote the follow:

          $string = $modx->documentObject['pagetitle'];
          $remove = array(' ', 'and', '&');
          $string = str_replace('$remove', '+', $string);
          return $string;
          


          Look okay?