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

    I have been frustrated by this for a while, but I'm finally getting around to posting.

    When you return a value from a custom output modifier, that is not a string with at least one character, the original output is returned by MODX.

    ?php
    $nowdate = date("Y-m-d");
    if ( strtotime($options) < strtotime($nowdate) ){
        return $input;
    }
    else {
        $input = "";
        return $input;
    }
    


    [[*introtext:pub=`01-dec-2015`]]
    


    Will simply print *introtext.

    ?php
    $nowdate = date("Y-m-d");
    if ( strtotime($options) < strtotime($nowdate) ){
        return $input;
    }
    else {
    // not the space
        $input = " ";
        return $input;
    }
    


    [[*introtext:pub=`01-dec-2015`]]
    


    Will not print anything - as expected.

    This seems fine until you want to write conditional modifiers like so (this is an arbitrary example for discussion):

    ?php
    if ( $input === $options ){
        return $input;
    }
    else {
        $input = null;
        return $input;
    }
    


    [[*field:matchcondition=`jp`:then=`Condition matched`]]
    


    Because :then is just seeing the original output returned.

    The only way to get around this is to use :is and :isn't to write in a string to check for:

    ?php
    if ( $input === $options ){
        return $input;
    }
    else {
        $input = "null";
        return $input;
    }
    


    [[*field:matchcondition=`jp`:isnt=`null`:then=`Condition matched`]]
    


    Is there a good reason why we cannot just return a false value and have the following clean conditional?

    [[*field:matchcondition=`jp`:then=`Condition matched`]]
    


    I realise that this is an incredibly low priority issue, it just seems very odd.
      • 3749
      • 24,544 Posts
      Custom output modifiers have never made much sense to me. Since you're going to be writing a snippet, why not write a dedicated snippet that does exactly what you want. It will be both easier and much faster since it avoids the notoriously slow tag parsing involved in conditional output modifiers.

      That said, many conditional output modifiers will behave strangely if you don't provide an :else clause. That could be involved in your issue.
        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