We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 6531
    • 154 Posts
    I'm using this code in several snippets to get data from the Vimeo API:

    require_once("__path__/vimeo-api/autoload.php");
    $vimeo = new \Vimeo\Vimeo(__auth keys__);
    $videos = $vimeo->request('/me/albums/'.$album.'/videos'.$options)['body']['data'];
    


    I pass to this snippet the arguments `$album` and `$options`. It returns an array.

    So what's the best way to call this 'child' snippet from another 'parent' snippet, passing the arguments, and then using the returned array in the 'parent' snippet?

    This question has been answered by danzg. See the first response.

      • 52064
      • 120 Posts
      $modx->runSnippet(string $snippetName [, array $params]);
        FerX - Developer at Eracom s.r.l.
        • 6531
        • 154 Posts
        Quote from: ferx77 at Jun 10, 2017, 03:22 PM
        $modx->runSnippet(string $snippetName [, array $params]);

        How do I get the result of calling runSnippet?

        An example would be helpful.

        Thanks
          • 6531
          • 154 Posts
          OK, I found the documentation: https://docs.modx.com/revolution/2.x/developing-in-modx/other-development-resources/class-reference/modx/modx.runsnippet

          $output = $modx->runSnippet('Welcome',array('name' => 'John'));
          echo $output; // prints 'Welcome John!'
          • discuss.answer
            • 6531
            • 154 Posts
            Wait a sec ... it says there "When you call a Snippet using runSnippet, the Snippet code is always executed: the results are never returned from cache. It's equivalent to running the Snippet using the [[!uncached]] syntax."

            So ... if I call [[SnippetA]] uncached, and SnippetA calls SnippetB with runSnippet ... does the 'parent' call to SnippetA get cached??

            I'm guessing YES. [ed. note: danzg last edited this post 6 years, 11 months ago.]
              • 3749
              • 24,544 Posts
              I agree, but it might complicate your plans that MODX snippets always return a string. I think that's true of runSnippet() as well. If you need an array, you might be able to pass it through a $_SESSION variable, though you might also be able to parse the returned string in SnippetA depending on its structure.
                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