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

    I encounter a problem when running a snippet from within another one using the $modx->runSnippet method.
    The output of the slave snippet must be returned to the main snippet, but it’s like the code was ran asynchroneously.

    In the following code, the "echo" from the slave snippet printed is after the $sortie of the master snippet.

    Also, $sortie shows that $resultat is empty, despite the $this->method_result from the slave snippet is not empty.
    It’s like the code of the master snippet finishes before the slave snippet sends its output.

    Thanks for any help.

    In the master snippet:
    $params['param1'] = '369';
    $params['param2'] = $item;
    $params['param3'] = 'some_method_name';
    $resultat = $modx->runSnippet("SomeSlaveSnippet",$params);
    $sortie =  '<br>--- Strangely '.$resultat.' variable resultat is not printed.---<br>'; 
    echo $sortie;


    In the slave snippet:
    case 'some_method_name' :
      $this->SomeMethodName();
      echo '<br>Result '.$this->method_result.' is printed.';
      return $this->method_result;
      break;