We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!

    • 12983
    • 108 Posts
    I do have a weird error, please let me know if it’s "normal" (and how to fix it) or if you have a clue on what I’m doing wrong.

    When I generate some string with a
    <a href...>
    link through parameter for a snippet, the output is truncated after the "e", that is I obtain:
    <a hre

    Please let me better explain this with a simple example.

    Let’s say this is my page content:
    <div>
    [!testsnippet?label=`MODX CMS` &link=`http://www.modxcms.com` &sign=` sign <a href="mailto:[email protected]">My Signature</a>`!]
    </div>
    


    And let’s say this is my testsnippet snippet:
    <?php
    
            $out = "<a href='".$link."' target='_new'>".$label."</a>";
            $out .= "<br />";
            $out .= "<a href='http://www.google.com'>google</a>";
            $out .= "<br />";
            $out .= $sign;
            echo $out;
    ?>
    


    Ok, nothing special. Sure? This is the output I obtain when loading the page:

    <div>
      <a href='http://www.modxcms.com' target='_new'>MODX CMS</a><br /><a href='http://www.google.com'>google</a><br /> sign <a hre
    </div>
    


    That is, everything’s ok but the last piece, which is just truncated after the e of href.

    Thanks for any help to fix this behaviour.
      • 8894
      • 114 Posts
      I’m not sure but it seems to me that there is a problem with ’=’ inside snippet parameters. So you should just avoid this. It should be fixed in MODx 097.
      • Yes, & and = are reserved characters in snippet calls (I believe they still will be in 0.9.7 as well). If you look at the snippet parameters, you can understand how this is so since it uses those characters to delimit the parameters and their values. There are two ways of dealing with it. You can write a wrapper snippet that uses runSnippet:
        $modx->runSnippet('testsnippet', array('label' -> 'MODX CMS', 'link' -> 'http://www.modxcms.com', 'sign' -> ' sign <a href="mailto:[email protected]">My Signature</a>'));
        

        OR you can use different characters to replace the & and = characters in your snippet tags, such as %% and @@, then use str_replace in the snippet code to switch them back.
          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
          • 7231
          • 4,205 Posts
          You can write a wrapper snippet that uses runSnippet
          Will this work for the & char? I guess so, wow, thanks, I was banging my head trying to use a & in a parameter, now I can resolve this. Is there no end to sotwell’s knowledge shocked
            [font=Verdana]Shane Sponagle | [wiki] Snippet Call Anatomy | MODx Developer Blog | [nettuts] Working With a Content Management Framework: MODx

            Something is happening here, but you don&#39;t know what it is.
            Do you, Mr. Jones? - [bob dylan]
            • 12983
            • 108 Posts
            Quote from: sottwell at Jan 18, 2008, 07:13 AM

            Yes, & and = are reserved characters in snippet calls (I believe they still will be in 0.9.7 as well). If you look at the snippet parameters, you can understand how this is so since it uses those characters to delimit the parameters and their values.

            Thanks. By the way I think the MODx parser could deal with both those characters, considering that the values are written into the "`" parenthesis... that is:

            &parameter=`whatever character different from the opening and closing char, so "=" and "&" too...`

            As long as the value does not contain the character "`", I think it could contain both "=" and "&".
            Am I wrong? If not, this should be fixed in 0.9.7 parser.
            • Hello insert_nick,

              The 097 parser is a completely different animal rewritten from the ground up and does not have this issue. See the MODx Next topic for more details.
                Ryan Thrash, MODX Co-Founder
                Follow me on Twitter at @rthrash or catch my occasional unofficial thoughts at thrash.me
                • 36592
                • 970 Posts
                Fixing core to enable using some special characters like ’&’, ’=’, ’?’ in snippet parameters was reported here.
                http://modxcms.com/forums/index.php/topic,3772.msg129335.html#msg129335