We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 42393
    • 143 Posts
    I've just created my first snippet called IsOldBrowser. It's intended as a more advanced IE6NoMore, doing a server-side check for old browsers and to get the client side to generate different HTML based on the result. The snippet is working. It returns a string 'true' when the browser is MSIE<=6 and 'false' for anything else. However, my evaluation of that result is not working. I'm sure someone here can point to my obvious syntactical error:

    [[!IsOldBrowser:is=`true` :then=`OLD` :else=`NEW`]]

    That's just the most simple form. Replace NEW and OLD with code and chunks for browsers you do and do not support, respectively.

    But what's happening is that when that is called it just displays the value 'true' or 'false'. The PHP does this:

    return $isOld ? 'true' : 'false';

    I don't want to display that literal. I want to evaluate that result and display something else.

    Another issue is that the snippet is executed twice on every page refresh. It's being called from the resource template - only one call in there of course. I see this in the Log report.

    I'm trying to learn proper syntax and snippet building as well as completing this contrived task. When complete I'll post this for others. It's value over IE6NoMore is that it's not just focused on IE, and it's not supposed to just return content (which unfortunately it's doing) but to allow the manager to determine the content, which I believe is more elegant. IE6NoMore renders a chunk of choice - this simply returns the result of some logic and then lets the UI decide what to do with that information. It's just another way of looking at the solution.

    Thanks!
      Loved ModX when I was using it a few years ago. Shifted to WordPress, sorry. Thanks, all.
      • 3749
      • 24,544 Posts
      You're comparing a boolean with a string wink. Try:

      :is=`1`


      or

      isempty
        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
        • 42393
        • 143 Posts
        Thanks for that.
        OK, I'm understanding from your note that IS does not mean EQ but !ISEMPTY.
        That doesn't agree with the doc.
        I tried EQ and ISEQUALTO, etc and those didn't work either.
        Sure, I can revise the snippet to return a null or non-null, but for this exercise I'd like to understand why comparing to that value is not working. Let's change the value to 'yes/no' rather than 'true/false'. That was just a random though logical choice of terms.
          Loved ModX when I was using it a few years ago. Shifted to WordPress, sorry. Thanks, all.
          • 3749
          • 24,544 Posts
          Sorry, I missed the quotes around 'true' and 'false' in your snippet. That should have worked.

          Yes, is= does mean equal (as PHP understands it).

          I tried these and both worked fine for me, so maybe something else is wrong.

          [[!Test:is=`true`:then=`OLD`:else=`NEW`]]
          
          // in the snippet:
          
          return $isOld ? 'true' : 'false';
          


          [[!Test:is=`1`:then=`OLD`:else=`NEW`]]
          
          // in the snippet:
          
          return $isOld ? true : false;



            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
            • 42393
            • 143 Posts
            Quote from: BobRay at Dec 27, 2012, 08:00 PM
            I tried these and both worked fine for me, so maybe something else is wrong.
            [[!Test:is=`true`:then=`OLD`:else=`NEW`]]
            Based on that I took a closer look. I had a space preceding the colons in my tag. I thought that was valid syntax but apparently not.

            So, THANK YOU VERY MUCH for taking the time to test that. It did help to verify how that works. I now have my first functional snippet. WOOT! smiley

            It's still executing the snippet twice for every page refresh. I found the cause. Since it's unrelated to this snippet I've opened a new thread.

            Thanks again. [ed. note: captainstarbuck last edited this post 13 years, 9 months ago.]
              Loved ModX when I was using it a few years ago. Shifted to WordPress, sorry. Thanks, all.
              • 3749
              • 24,544 Posts
              I'm glad you got it sorted. Thanks for reporting back.
                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