We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 577
    • 132 Posts
    I have just had the strangest snippet experience and even after a night of sleeping on it thinking it was all me (maybe still is) , I have come back to the same results.

    I do not see how the code in the snippet would play any part in this so I will summarize. The overall end result (failure) is the nothing is ever returned by the snippet and/or blank is always returned.. not sure.

    Snippet
    
    $output = '';
    
    ........... code hear ............
    $output = 'Adam';
    
    return $output;
    


    The result is nothing returned. The page itself is resolving and all the page content above and below returns but the area where the snippet is does not get placed.

    Now my first thought is of course snippet is not running, tag is bad, cache is stuck. Tried all those. Cleared Cache. Open FS and even emptied all files/folders in ./core/cache.

    And if I do this
    
    $output = '';
    
    ........... code hear ............
    $output = 'Adam';
    
    echo $output;die;
    
    return $output;
    


    I get the echo of $output just one line before it is suppose to be returned.

    Also this has no positive effect
    
    $output = '';
    
    ........... code hear ............
    $output = 'Adam';
    
    return 'ADAM';
    


    So this was my solution and it works... but what is going on

    
    $output = '';
    
    ........... code hear ............
    $output = 'Adam';
    
    $modx->setPlaceholder('mySnippet',$output);
    
    return '';
    


    Resource
    
    [[!mySnippetTag]]
    [[+mySnippet]]
    


    Call me crazy or overworked. Both probably fit.

    Update: All tag names are for demo only they are not my actual tag names...
      "One of these days I will get around to my own website... Its only been about 12 years... maybe tomorrow smiley"
      • 3749
      • 24,544 Posts
      Is your snippet actually called runSnippet? That’s the name of a MODX method, so not a good name for a snippet.
        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
        • 577
        • 132 Posts
        No it was just for explanation but I see how that was not very clear. I will change smiley

        This is the actual call

        [[!ras.getPickPlays? &relType=`Totals`]]
        
        [[+ras.gamePlayResults]]
        
          "One of these days I will get around to my own website... Its only been about 12 years... maybe tomorrow smiley"
          • 3749
          • 24,544 Posts

          Feel free to post the whole snippet.
            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
            • 577
            • 132 Posts
            Ok I know have a second snippet doing the same thing as the first. This is only 2 out of 14 snippets doing this as well as in formIt I have custom prehooks returning true with no problem but all my custom hooks will not return true.

            Now I am running the snippets and hooks through includes to external sources. However as I show above that setup works fine for most.

            On a side note I did copy all code into modx manager and removing the included external snippet file and it still did not return anything

            Setup is
            require_once($modx->getOption('modx.ras').'/snippets/ras.releaseQueue.php');
            


            This is the snippet code
            <?php
            
                $output = '';
                
                $ras =& $modx->raspicks;
                
                $gameInfo = array();
                
                if(!empty($_REQUEST['handicapper']) && !empty($_REQUEST['handicapper'])){
                    $picks = $ras->getReleasedPicks($_REQUEST['handicapper'],$_REQUEST['sport']);
            
                    if(!empty($picks)){
                        foreach($picks as $pick){
                            
                            $games = $ras->getGamesFromReleaseId($pick);
                            
                            if(!empty($games)){
             
                                foreach($games as $game){
            
                                    if($game['pick_r2g_type'] != 'Quick Message'){
                                        $gameInfo[] = $ras->setGamePick($game,$pick['pick_rel_datetime']);
                                    }
                                }
                            }
                            
                        }
                    }
                }
            
                $picks = '';
                if(!empty($gameInfo)){
                    
                    foreach($gameInfo as $info){
                        
                        $params = array(
                        'relTime'    => date('Y-m-d H:i:sa',$info["releaseTime"]),
                        'date'       => date('Y-m-d',$info["datetime"]),
                        'time'       => date('H:i:sa',$info["datetime"]),
                        'relType'    => $info["relType"],
                        'gamenumber' => $info["game"],
                        'matchup'    => $info["gameName"],
                        'rating'     => $info["rating"]
                        );
                        
                        $picks .= $modx->getChunk('ras.pickReleaseQueue_Row',$params);
                    }
                }
            
                if($picks != ''){
                    $output = $modx->getChunk('ras.pickReleaseQueue_Table',array('picks'=>$picks));
                }
            
                return $output;
            


            Again if I echo the $output 1 line above the return it has data. My only solution has been to put it all in a placeholder and then add the placeholder tag below the snippet tag
              "One of these days I will get around to my own website... Its only been about 12 years... maybe tomorrow smiley"
              • 3749
              • 24,544 Posts
              I don’t see anything wrong with the code, although I’ve never seen a snippet with a dot in the name before. That could be confusing the parser when it tries to replace the snippet tag with the return value.
                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
                • 577
                • 132 Posts
                I will change the name just for giggles and see what happens. There are plenty of others with dots and no issue but anything is worth a try.

                Also looks like I am not alone (possibly)

                here is someone with a similar issue though of course it could be totally unrelated.
                http://modxcms.com/forums/index.php/topic,67400.0.html
                  "One of these days I will get around to my own website... Its only been about 12 years... maybe tomorrow smiley"
                  • 577
                  • 132 Posts
                  Ok renamed it just to say I did and it made not diff
                    "One of these days I will get around to my own website... Its only been about 12 years... maybe tomorrow smiley"
                    • 3749
                    • 24,544 Posts
                    The first thing I’d do is add an else for every if:

                    else {
                    
                       return 'Picks is 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
                      • 577
                      • 132 Posts
                      Understood, however I am 100% positive that the issue is not the out being empty.

                      This will show that there is data in $output;
                      echo $output;die;
                      return $output;
                      


                      This is my work around
                      $modx->sePlaceholder('myPlaceholder',$output);
                      return '';
                      


                      But this returns nothing every time.
                      return $output;
                      


                      And this as well
                      return 'adam';
                      


                      There is something going on with the way things are sometimes being parsed. Its like the return does not exist and the function result is void.
                        "One of these days I will get around to my own website... Its only been about 12 years... maybe tomorrow smiley"