We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
  • I ran into a very simple issue when creating snippets and plugins. When you need to add a value to the document’s URL for processing on refresh or loading another document, always make sure to use &key=value. The document’s base URL will already have the ?id=xx (index.php?id=xx) which gets rewritten if Friendly URLs are used. If you forget this and add your extra values with another ? instead of & it can cause some odd "bugs", particularly if Friendly URLs are not being used.
      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
      • 18397
      • 3,250 Posts
      My simple way is to detect if furls are on or off and use the appropriate character. See NewsListing 4.3.1 for an example.
      • Thanks! Blatantly ripped off the code in the NewsListing snippet and popped it into the ShopCart snippet (well, I used my favorite ternary operator, but it’s the same logic).

        $furls = $modx->config['friendly_urls'];
        $char = $furls ? '?' : '&';
        


        At this point, the TemplateSwitcher links are hand-coded in a chunk, so I need to remember to use whichever character is appropriate for the site in question. Eventually, however, I’ll have a snippet to automagically generate the links from the templates available, and this code will come in handy.
          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