We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 14772
    • 14 Posts
    If I want to include a php snippet inside another php snippet what would be the format?

    I have [[functions]] - functions being the name of the snippet within another snippet, but it does not seem to be working.... I want it to work like a regular php include or require.

    Thanks
    Josh

      • 28042 ☆ A M B ☆
      • 24,524 Posts
      A snippet is just plain php code that is passed through the eval() php function. So to include external php files, use an include, include_once, require, require_once function just as you would in any other php code. Keep in mind that a snippet behaves much like a php function, so any output needs to be returned. Echo and print statements do work, but can sometimes behave unexpectedly. Better to gather such output into a variable, then return the variable.
        Studying MODX in the desert - http://sottwell.com
        Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
        Join the Slack Community - http://modx.org
        • 33337
        • 3,975 Posts
          Zaigham R - MODX Professional | Skype | Email | Twitter

          Digging the interwebs for #MODX gems and bringing it to you. modx.link
          • 14772
          • 14 Posts
          Ok thanks, I am just a little confused on how to implement API??

          I am placing this in my php code:

          runSnippet("snippet_name");


          but the script is saying undefined function?

          What am I doing wrong?

          Thanks!
            • 28042 ☆ A M B ☆
            • 24,524 Posts
            If this is in a snippet, you use
            $modx->runSnippet('snippetName', array('option1'=>'value1', 'option2'=>'value2));

            The array of options and values match the parameters you would normally use in the snippet tags.
              Studying MODX in the desert - http://sottwell.com
              Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
              Join the Slack Community - http://modx.org