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

    I have following problem:

    In one of my resources I want to check if a specified GET-Parameter exists and if so, modify the output. The Snippet I created to get the GET-Parameter is

    $return = 'empty';
    
    if(isset($_GET[$field])){ $return = $_GET[$field];}
    
    return $return;


    The resource call is

    [[[[!GET? &field=`year`]]:is=`empty`then=`foo`:else=`bar`]]


    If I set the GET-Parameter, it prints "bar", but if not, it prints nothing.
    Does anybody got an idea why not?

    I appreciate every clue smiley

    Regards
      • 3749
      • 24,544 Posts
      Try this one-line version:


      return isset($_GET[$field]) && (!empty($_GET[$field]))? $_GET[$field] : 'empty';

        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
        • 44154
        • 6 Posts
        Hey Bob,

        thanks for your reply! Unfortunatly that didn't work for me.
        Any other suggestions?

        Regards
          • 4041
          • 788 Posts
          Is there a missing : before then=`` in your resource call?
            xforum
            http://frsbuilders.net (under construction) forum for evolution
            • 44154
            • 6 Posts
            Hey breezer,

            actually it was, but somehow it didn't changed anything. I'll paste my current code again:

            GET-Snippet:
            $return = '';
             
            if(isset($_GET[$field]) && !empty($_GET[$field])){ $return = $_GET[$field];}
             
            return $return;


            Resource-Call:
            [[+[[!GET? &field=`year`]]:is=``:then=`'foo'`:else=`'bar'`]]


            but now i have a really strange behavior:

            if i HAVE a GET-Parameter, it shows 'foo', when it actually shouldn't. when i dont have any get-parameter, it stays empty. See in action here: http://s400814763.online.de/index.php?id=24.

            click at the top on the years (2011, 2012, 2013) etc, to set a get-prameter.

            regards
              • 44154
              • 6 Posts
              Got it. Solution is to call the modifiers BEFORE passing the values, like this:

              [[!GET:is=`empty`:then=`'foo'`:else=`'bar'`? &field=`year`]]


              Thanks for your help!