We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 15309
    • 30 Posts
    how to pass url’s to snippets having ’?’ in it.
    like i want to pass an url(http://www.mysite.com/index.php?id=11) to my snippet ..

    while i pass a ’?’ in a variable it crashes the page..with a parser error..
    « MODx Parse Error »
    MODx encountered the following error while attempting to parse the requested resource: 
    « PHP Parse Error » 
      
    PHP error debug 
      Error:  fopen(http://in.answers.yahoo.com/rss/catqsi) [function.fopen]: failed to open stream: HTTP request failed! HTTP/1.1 404 Not Found    
      Error type/ Nr.:  Warning - 2   
      File:  E:\......\manager\includes\document.parser.class.inc.php(766) : eval()'d code   
      Line:  29   
      
    Parser timing 
      MySQL:  0.0192 s (9 Requests) 
      PHP:  1.4730 s   
      Total:  1.4923 s   
    Error while inserting event log into database.
    

    please suggest.. huh
      • 28042 ☆ A M B ☆
      • 24,524 Posts
      Snippets cannot have ? & or = in their parameters, since they are used by the snippet to parse the parameter string.

      There are two solutions to this.

      1. Use something like ||q|| and ||e|| and ||a|| in the parameter string, and replace them with the appropriate symbols in your snippet.

      2. Use a wrapper snippet:
      $modx->runSnippet('MySnippet', array('url',=>'http://www.domain.com/index.php?id=xxx', 'param2'=>'value2'))


      However, in the case of passing a link to a MODx page, you can use [~11~] and let MODx generate the URL for you.
      [[MySnippet? &url=`[~11~]`]]
        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
        • 33372
        • 1,611 Posts
        If you only need to pass URLs for pages on your site, then I would just pass the document id (e.g., [[MySnippet? &docID=`11`]]) and either use $modx->makeURL($docID) in your snippet or just output it as ’[~’.$docID.’~]’ and let the parser do it for you.
          "Things are not what they appear to be; nor are they otherwise." - Buddha

          "Well, gee, Buddha - that wasn't very helpful..." - ZAP

          Useful MODx links: documentation | wiki | forum guidelines | bugs & requests | info you should include with your post | commercial support options