We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 21258
    • 14 Posts
    I’m trying to pass a url with query as a parameter in a snippet call but it is being modifed before I recieve it in the actual snippet.

    Example snippet call:
    [!mysnippet? &url=`http://www.example.com/mysite/Show?pid=4&mid=8`!]

    The &url parameter recieved in the snippet:
    http://www.example.com/mysite/Showpi


    The ? is stripped out and the string is terminated 1 character before the = sign.

    Is it possible to pass through a string of text like this in a snippet call without it being modified?

    Any help would be greatly appreciated.
      • 3749
      • 24,544 Posts
      The parser doesn’t like question marks, ampersands and equals signs in parameters.

      One solution is to encode them in the tag and then decode them in the snippet:


      [
      !mysnippet? &url=`http://www.example.com/mysite/ShowQUESTIONpidEQUALS4AMPERSANDmidEQUALS8`!]

      Then in the snippet:

      <?php
      $search = array('QUESTION','AMPERSAND','EQUALS');
      $replace = array('?','&','=');
      
      $url = str_replace($search,$replace,$url);
      ?>
        Did I help you? Buy me a beer
        Get my Book: MODX:The Official Guide
        MODX info for everyone: http://bobsguides.com/modx.html
        My MODX Extras
        Bob's Guides is now hosted at A2 MODX Hosting
        • 21258
        • 14 Posts
        Thanks BobRay, that’s a nice solution.

        I messed around with it myself and put the query section of the url in another parameter.

        Snippet Call:
        [!mysnippet? &url=`http://www.example.com/mysite/Show` &query=`pid|4, mid|8`!]


        Snippet Code:
        if(trim($query) != "") {
           $url .= "?";
           $query_array = explode(',',$query);
           for ($q=0;$q<count($query_array);$q++) {
              $qtemp = explode("|",$query_array[$q]);
              if($q != 0) {$url .= "&";}
              $url .= trim($qtemp[0])."=".trim($qtemp[1]);
           }
        }


        Not as elegant as your solution but hey... it works for me.
          • 3749
          • 24,544 Posts
          Glad you got it working. smiley
            Did I help you? Buy me a beer
            Get my Book: MODX:The Official Guide
            MODX info for everyone: http://bobsguides.com/modx.html
            My MODX Extras
            Bob's Guides is now hosted at A2 MODX Hosting