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

    I was simply on my way testing if a tv was empty or not to output a chunk OR another
    The 1st try was done using modifier:
    [[*page-illustration:!empty=`do this`:empty=`do that`]]
    

    I this seams to be ok, BUT it outputs the page-illustration TV content as I never call it into the 'do this or do that'. part
    (very strange right?)



    Thank you
      • 27708 MODX Staff
      • 2,502 Posts
      The empty or default output modifier will output the TV value if there is a value. It doesn't work the same way as the !empty which will output only what is explicitly passed. I don't know if this is the intended behaviour but see the following example:

      Your
      [[*page-illustration:]] has a value of /image.jpg

      [[*page-illustration:!empty=`do this`:empty=`do that`]]

      and you'd expect in this case it would return: "do this" but the way the empty output modifier works is that it will be hit second and because the value is false it returns the TV value.

      It may work if you reverse the order but I doubt it. In this case you have two options: install the If snippet and use the following syntax:
      [[If? &subject=`[[*page-illustration]]` &operator=`empty` &then=`do this` else=`do that`]]

      Or you can use a slightly modified Output filter:
      [[*page-illustration:is=``:then=`do this`:else=`do that`]]
        Author of zero books. Formerly of many strange things. Pairs well with meats. Conversations are magical experiences. He's dangerous around code but a markup magician. Blog ✦ Twitter ✦ LinkedIn ✦ GitHub
        • 3749
        • 24,544 Posts
        An alias of 'empty' is 'default', which makes it easier for me to remember that it either returns the item or, if it's empty, returns the default value. i


        ------------------------------------------------------------------------------------------
        PLEASE, PLEASE specify the version of MODX you are using.
        MODX info for everyone: http://bobsguides.com/modx.html

          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
          • 36604
          • 268 Posts
          Ok thanks a lot. I'm gonna use the the:is=`` solution.

          There's still my second thread pending with how to get an empty value by default for a @directory binding..