We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 38471
    • 6 Posts
    Using MODx 2.2.0-pl2, I have the following in a template:

    [[If?
    					&subject=`[[*parent]]`
    					&operator=`EQ`
    					&operand=`69`
    					&then=`
    						<h3>Previous Versions</h3>
    						[[!AudioPlayer? &parentid=`[[*id]]`]]
    						<h3>Recording Sessions</h3>
    						[[!SessionLinks? &parentid=`[[*id]]`]]
    					`
    				]]
    			
    				[[If?
    					&subject=`[[*id]]`
    					&operator=`EQ`
    					&operand=`36`
    					&then=`
    						<h3>Latest Updates</h3>
    						[[!getResources?
    							&tpl=`tplSolutionNew`
    							&parents=`36`
    							&sortby=`editedon`
    							&limit=`15`
    						]]
    						`
    				]]
    


    When pages whose parent is 69 are loaded, the first if executes as expected (the two snippets called are custom snippets that output a media player based on child static resources, and a list of YouTube videos, based on child static resources.

    When Resource ID 36 is loaded, I get nothing but a blank page.

    If I remove the first if call, Resource ID 36 loads and the getResources snippet runs as expected.

    I have switched the order of the two statements and nothing changes.

    I have tried calling the ifs uncached and the inside snippets cached and nothing changes.

    Nothing is added to the MODx error log when #36 doesn't load.

    If I remove the two custom snippet calls from the first if, both #36 and child pages of #69 load, but obviously the functionality of the snippets is lost. However, if I remove the other if, the snippets execute just fine.

    I can post the custom snippets if necessary, but literally all they do is put a string together and return it. Nothing is 'echo'ed, there are no weird break statements or anything. Just string manipulation, $r = ""; $r .= "foo"; $r .= "bar"; return $r. I am using the API to pull some resources but nothing is written back to the database.

    I really don't understand why this doesn't run. Any help would be appreciated.
      • 38471
      • 6 Posts
      Answered the question myself.

      Turns out MODx executes ALL snippets in &then parameters of If snippet, even if the if snippet won't evaluate true.

      The custom snippets were trying to get particular records that didn't exist underneath #36, and when the snippet tried to work on an object that didn't get created, MODx died.

      Wrapping all of the snippet after the code that tries to create the object in "if ($object) { ... }" seems to do the trick.
        • 18373 ☆ A M B ☆
        • 3,141 Posts
          Mark Hamstra • Developer spending his days working on Premium Extras and a MODX Site Dashboard with the ability to remotely upgrade MODX and extras to make the MODX world a little better.

          Tweet me @mark_hamstra, check my infrequent blog at markhamstra.com, my slightly more frequent ramblings at MODX.today or see code at Github.