We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 6841
    • 61 Posts
    I have already posted this in the Snippets forum because I thought it was a problem with the NewsListing snippet, but I’ve been advised that’s it’s a parser issue, so I’m reposting here:

    I’m trying to set up a site in Spanish, and I need to be able to put an accented character in the &truncText parameter of the NewsListing. This is what I’ve got right now...
    [!NewsListing? &tpl=`NewsListingTemplate` &startID=`2` &truncText=`Lea más...` &summarize=`99`!]
    

    Problem is that everything after the word "Lea" is ignored, so it is only rendered as "Lea " (including the space).

    Is there anything that I can do to fix this? Do I need to file a bug report? If I need to come up with a fix myself, can someone at least point me to the right file?

    Thanks.
      Dave
      • 22303 MODX Staff
      • 10,725 Posts
      Quote from: ddecjc at Apr 03, 2006, 04:51 PM

      Is there anything that I can do to fix this? Do I need to file a bug report? If I need to come up with a fix myself, can someone at least point me to the right file?

      Yes, please file a bug report for this and I will take a look and try and slip it in the pending release. If you’re interested in looking and contributing potential solutions, feel free to take a look at /manager/includes/document.parser.class.inc.php, and start with the parseProperties() function.
        • 6841
        • 61 Posts
        Bug report filed as FS#334. I listed severity as medium because it probably doesn’t happen often enough to be high or critical for the general population. For me, however, it is critical. Thanks for looking at it. I will also try to take a look at the code you mentioned.
          Dave
          • 6841
          • 61 Posts
          I looked in document.parser.class.inc.php and found the source of the problem. It is on line 763 in the evalSnippets function.
          $tempSnippetParams = split($splitter, $tempSnippetParams);
          

          When this line is executed to split the parameters into an array, the splitter is the "&" character. Since the html representation of many special character contains an "&" (for example, the html source for á is á), an unintended split occurs which results in the parameter string for
          [!NewsListing? &tpl=`NewsListingTemplate` &startID=`2` &truncText=`Lea más...`!]
          

          being split into
          $tempSnippetParams = array(6) {
            [0]=>
            string(1) " "
            [1]=>
            string(26) "tpl=`NewsListingTemplate` "
            [2]=>
            string(12) "startID=`2` "
            [3]=>
            string(16) "truncText=`Lea m"
            [4]=>
            string(13) "aacute;s...` "
            [5]=>
            string(13) "summarize=`1`"
          }
          

            Dave
            • 22303 MODX Staff
            • 10,725 Posts
            Quote from: ddecjc at Apr 04, 2006, 07:01 AM

            I looked in document.parser.class.inc.php and found the source of the problem. It is on line 763 in the evalSnippets function.
            $tempSnippetParams = split($splitter, $tempSnippetParams);
            


            Try adding this line right before the line above with the split() call:

            $tempSnippetParams = html_entity_decode($tempSnippetParams, ENT_NOQUOTES, $this->config['etomite_charset']);
            


            This seems to work for me, but I haven’t tested it exstensively yet. If that doesn’t work, try simply turning off the rich-text editor for a moment and pasting the code directly into the content source. This will prevent the RTE from converting the special characters to HTML entities when being saved to the DB.
              • 6841
              • 61 Posts
              Quote from: OpenGeek at Apr 04, 2006, 10:18 AM
              Try adding this line right before the line above with the split() call:
              $tempSnippetParams = html_entity_decode($tempSnippetParams, ENT_NOQUOTES, $this->config['etomite_charset']);
              That did the trick. Thanks!

              Quote from: OpenGeek at Apr 04, 2006, 10:18 AM
              If that doesn’t work, try simply turning off the rich-text editor for a moment and pasting the code directly into the content source. This will prevent the RTE from converting the special characters to HTML entities when being saved to the DB.
              Doh! I didn’t even think about it being stored that way because of the RTE. I was thinking that it got converted to html entity during parsing.

              Thanks again!
                Dave
                • 36805
                • 354 Posts
                Why can’t i call a snippet and initialize a parameter with a special character?
                like [[MySnippet? &myVar=`abc¡de`]]
                If i do in the snippet the variable content is truncated and if i return it, it is merely abc

                We’re running 0.9.6 on PHP Version 5.2.3 so the fix discussed in this thread should be allready applied correct?
                However it looks like I still have trouble with this: http://modxcms.com/bugs/task/334
                  • 22303 MODX Staff
                  • 10,725 Posts
                  This has always been a known limitation of snippet parameter values; you cannot use ? & or =.

                  The problem has been addressed for 0.9.7 release.
                    • 36805
                    • 354 Posts
                    Quote from: OpenGeek at Dec 11, 2007, 10:14 AM

                    This has always been a known limitation of snippet parameter values; you cannot use ? & or =.

                    The problem has been addressed for 0.9.7 release.
                    I was experiencing the bug with ñ, ¿, ¡, á and the list goes on, not just the operators you listed.

                    Edit: just after posting it crossed my mind that every html encoded character obviously contains a & rolleyes My bad smiley

                    I ended up doing what you described earlier in this thread (switching the MODx document to non-rte, save, replace the html encoded chars with non encoded versions, save, switch back to rte). Thank god it were only 3 pages this time around smiley
                      • 28042 ☆ A M B ☆
                      • 24,524 Posts
                      That’s the RTE being overly helpful; you can stop that in the plugin configuration; change one of the settings to ’raw’ (I forget exactly which setting that is).

                      Not being able to use & and = in snippet parameters is another matter; it has to do with how snippet parameters are parsed. You can work around that by making a "wrapper" snippet that only has
                      $modx->runSnippet('snippetName', array('param1'=>'value1', 'param2'=>'value2'));
                      return '';
                      
                        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