We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 31337
    • 258 Posts
    So I *still* don’t understand why that snippet needs a literal ’=’ passed to it, but ok...let’s move on grin

    The easiest way to work around this is to use some text that you’re guaranteed to never see otherwise and use that as a placemarker for the ’=’. An example might be easier. Call your snippet this way:
    [!test? &var=`<a hrefXXXX"index.htm"`!]


    Notice that ’XXXX’ is used instead of a literal ’=’. Then in your snippet, the first thing you do is:
    $var = preg_replace('/XXX/','=',$var);


    Yes I agree it’s an ugly hack, but it seems like a quick workaround until the real problem is fixed.
      • 5282
      • 147 Posts
      Quote from: vbrilon at Dec 25, 2005, 02:05 AM

      So I *still* don’t understand why that snippet needs a literal ’=’ passed to it, but ok...let’s move on grin

      just because i need to pass html tags in the variables smiley, for example html links need equal signs ( href=... )

      ( sorry my english isn’t perfect :s )

      wendy i didn’t really understand what you meant, you suggest that i use a chunk within the snippet ?
      i think i’m gonna use the regex solution

      merry christmas !
        i’m not a native english speaker, sorry if there are any mistakes ! smiley

        Pikkitux.com Website about Ubuntu Linux, Website Creation, and many other how-tos, tips and tricks ... ( French Language, and of course Modx Powered ! )
        • 28042 ☆ A M B ☆
        • 24,524 Posts
        Yes, pass the name of the chunk (&var=`ChunkName`), then in the snippet do

        $link = $modx->getChunk($var);
        


        You can put whatever you want in the chunk, even including snippet tags!.


          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
          • 10472
          • 22 Posts
          Using a chunk prevents truncation at a the equals sign, but not at a ’less than’ sign.

          I’m looking for a way to pass an SQL statement as a string variable, but both snippet variables and chunks seem to fail. Here’s the string I’m trying to pass:

          where LENGTH(Customer)=4 and Passed<NOW()
            • 28042 ☆ A M B ☆
            • 24,524 Posts
            There are two ways you can handle such issues. Either use a different symbol, and have a line in the snippet with a str_replace function to convert the symbol back to what you want, or create a second snippet that only has a call to runSnippet, with the values you want in the params array:
            return $modx->runSnippet('MySnippet', array('param1'=>'where LENGTH(Customer)=4 and Passed<NOW()', 'param2'=>'value2');
            
              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
              • 30481
              • 33 Posts
              In the future it would be possible to pass the equal character in snippet parameter ?

              I can explain why I need to use it.
              I am doing a snippet to make the call to a audio streaming reader, and i need to pass the location of the audio file. Sometimes, this audio file link gets php parameter inside it (like some download link on mysapce for example..), so gets some = .... and also some & !
              for example: http://mp3download.myspace.com/music.ashx?bandid=133264151&songid=38014414&name=133264151_136b3be0

              I need to pass this in a parameter. The parameter stop on the caracter before the first =.
              I think that if the problem with the = does’nt exist anymore I will have also a problem with the & ?

              Modx does’nt use the ` characters to find the content of a snippet parameter ?
                -------------------------------
                www.fabienletort.com
                • 30504
                • 14 Posts
                This bug easily can be solved (still actual for MODx 0.9.5). I placed the solution as a comment of the bug-report (http://modxcms.com/bugs/task/798?tasks=reported).
                But I better repost it here:
                change code in document.parser.class.inc.php. The problem is in evalSnippets function of DocumentParser class.
                Original part of code (MODx 0.9.5) of this function looks like:
                function evalSnippets($documentSource) {
                ...
                  $snippetParamCount= count($tempSnippetParams); // Find this place of code. It's near the end of function
                  for ($x= 0; $x < $snippetParamCount; $x++) {
                    if (strpos($tempSnippetParams[$x], '=', 0)) {
                    if ($parameterTemp= explode("=", $tempSnippetParams[$x])) { // here's the problem!
                      $fp= strpos($parameterTemp[1], '`');
                      $lp= strrpos($parameterTemp[1], '`');
                      if (!($fp === false && $lp === false))
                        $parameterTemp[1]= substr($parameterTemp[1], $fp +1, $lp -1);
                      $parameter[$parameterTemp[0]]= $parameterTemp[1];
                    }
                  }
                ...
                }
                

                To fix problem this part of code should be changed to:
                function evalSnippets($documentSource) {
                  ...
                  $snippetParamCount= count($tempSnippetParams);
                  for ($x= 0; $x < $snippetParamCount; $x++) {
                    $param = $tempSnippetParams[$x];
                    $eqPos = strpos($param, '=', 0);
                    if ($eqPos) {
                      $parameterTemp[0] = substr($param, 0, $eqPos);
                      $parameterTemp[1] = substr($param, $eqPos+1);
                
                      $fp= strpos($parameterTemp[1], '`');
                      $lp= strrpos($parameterTemp[1], '`');
                      if (!($fp === false && $lp === false))
                        $parameterTemp[1]= substr($parameterTemp[1], $fp +1, $lp -1);
                      $parameter[$parameterTemp[0]]= $parameterTemp[1];
                    }
                  }
                ...
                } // end of method
                

                Now it’s safe to use equals sign (’=’) in parameter values.
                  • 30525
                  • 9 Posts
                  This is an old thread, but it seems the problem is still not resolved: I have a snippet that needs to accept a multi-dimensional array as a parameter, such as
                  $field_array = array(
                  	'year' => array('textBox','Year','','5',1,'Please enter a year'),
                  	'semester' => array('dropdown','Semester',array(1=>array('1','selected'),2=>array('2','selected')),'','')
                  );
                  

                  The snippet then calls an eval() on the array value, creating a variable $field_array within the snippet.

                  I’m having the same problem described in this post earlier: with the default MODx installation, the snippet only ever gets "$field_array " passed into it. I modified the document.parser.class.in.php file as described, and now I get "$field_array = array(’year’ " - it gets stuck on the second equal sign.

                  If I store the code as a chunk, and call that into the variable, the page just spits the snippet call back at me, without evaluating it.

                  Any ideas on what’s going on here? Currently, I’m dealing with simple two-dimensional arrays by passing them in as a listlist, but this doesn’t quite work if the entries can be two-dimensional arrays such as the one above...

                  Thanks,
                  Jan
                    • 22303 MODX Staff
                    • 10,725 Posts
                    In Revolution, you can do this, but in 0.9.6.x or earlier, you’re going to have to use some kind of character substitution, hack the core (the way toxxic did), or use a wrapper snippet that declares the multi-dimensional array and is passed using $modx->runSnippet(’snippetname’, array(’foo’ => array(1,2,3,4)));