We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 29861
    • 59 Posts
    I use the If snippet but I understood that the = caracter is forbidden inside the snippet parameters so I added those lines in the snippet:

    // Custom replace forbidden caracteres in $then and $else
    $search = array('@eq@');
    $replace = array('=');
    $then = str_replace($search,$replace,$then);
    $else = str_replace($search,$replace,$else);


    Does modx have a predefine function to do this?
      • 22303 MODX Staff
      • 10,725 Posts
      Actually, ? & = is fine in a snippet parameter value in MODx Revolution as long as it appears within the backticks, just not in Evolution.
        • 29861
        • 59 Posts
        Well something is wrong, or I may have encountered a bug because the following line isn’t working (it sends back an empty content page, not an empty page):
        [[!If? &subject=`[[!+warning_user]]` &operator=`eq` &operand=`1` &then=`checked="checked"`]]

        And if I put my little str_replace script, the following works:
        [[!If? &subject=`[[!+warning_user]]` &operator=`eq` &operand=`1` &then=`checked@eq@"checked"`]]


        Any side effect?
          • 22303 MODX Staff
          • 10,725 Posts
          I’d have to know what other code was involved to help.
            • 29861
            • 59 Posts
            I simplified my code and here is how it works:

            The template used:
            [[$html?
              &contentChunk=`[[*content]]`
            ]]


            The chunk ’html’:
            <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
            <html xmlns="http://www.w3.org/1999/xhtml" lang="en">
            <head>
            <title>[[++site_name]] - [[*pagetitle]]</title>
            <base href="[[++site_url]]" />
            </head>
            <body>
                [[+contentChunk]]
            </body>
            </html>


            The resource content:
            Just a word<br />
            [[!If? &subject=`1` &operator=`eq` &operand=`1` &then=`checked="checked"`]]


            Like that it DOESN`T work. The result:
            <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
            <html xmlns="http://www.w3.org/1999/xhtml" lang="en">
            <head>
            <title>GalileoActive - test2</title>
            <base href="http://localhost/active/ga/" />
            </head>
            <body>
                
            </body>
            </html>

            Note that the words ’Just a word’ aren`t displayed either.

            If I change [[+contentChunk]] by [[*content]] in the chunk ’html’ as following:
            <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
            <html xmlns="http://www.w3.org/1999/xhtml" lang="en">
            <head>
            <title>[[++site_name]] - [[*pagetitle]]</title>
            <base href="[[++site_url]]" />
            </head>
            <body>
                [[*content]]
            </body>
            </html>


            It WORKS huh

            Any idea of what`s happening?
              • 22303 MODX Staff
              • 10,725 Posts
              Not exactly sure why, but I’ll investigate and let you know. Most likely it’s just a complication of parse order.
                • 31471
                • 206 Posts
                The problem I’m facing width, may be for a similar reason/bug like yours:
                http://modxcms.com/forums/index.php/topic,41621.msg297014.html#msg297014
                  • 29861
                  • 59 Posts
                  Have you tried inserting the script from the 1st post at the beginning of If Snippet code and replace the = by @eq@ ?
                  That’s what I did to make it work.
                    • 31471
                    • 206 Posts
                    I can workaround it by moving the inner If into a chunk, but I think it _should_ work in the combined way.