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

    I have a problem with snippets when I use a parameter that contains the character &

    [[ mysnippet? &str=`ab&cd` ]]
    


    In "mysnippet" code, $str variable contain only the half of the supplied string (ie "ab"), it stops at the first character & met.

    Can someone explain to me why? and if there is a way to supply strings containing & ?


    Thank you
    Hamza

      • 28042 ☆ A M B ☆
      • 24,524 Posts
      The snippet itself uses ? & and = as its parameter delimiters. You can use a substitution, such as |a|, and in your snippet code replace the |a| with &.

      Or you can use a wrapper snippet, calling your snippet with the $modx->runSnippet(’mysnippet’, array(’str’->’ab&cd’));

      Yet another way to deal with this is to have your snippet use an external config file, with the name of the config file passed as a snippet paramter (&config=`filename`) and your snippet includes that file if the parameter is set (and the file exists!) Since such a config file is just a plain-vanilla .php file that defines PHP variables, you can use & for the variable definition values all you like.
        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
        • 11713
        • 11 Posts
        thank you for your response,
        but it is not practical to check every string before giving it to a snippet.
        normaly in most languages there is a character like ’\’ making possible to display or use a reserved character without any problem.

        i hope that in future releases, modx can stand that.

        Best regards
        Hamza
          • 3749
          • 24,544 Posts
          Most snippets don’t need that so it would waste time and processing power to have the MODx core check every argument and make the substitutions.

          It’s easy enough, and much more efficient, for you to use an alternative (e.g. EQUALS, AMPERSAND, QUESTION) in the parameter and make the substitution in the snippet itself when necessary.
            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