We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 18397
    • 3,250 Posts
    Yeah. Just use a template containing only my GrabPage snippet and then you can avoid copying and pasting.
      • 4673
      • 577 Posts
      Sweet! That’s exactly what the doctor ordered.

      Thanks!
        Tangent-Warrior smiley
        • 18397
        • 3,250 Posts
        Your welcome
          • 21301
          • 93 Posts
          Quote from: xwisdom at Aug 02, 2005, 12:37 PM

          ob_start()
             include "whatere.php";
             startApp(); // here my app uses echo to output text
             return ob_get_content();
          ob_end_clean();

          Great tip, I use it all the time, thanks!
          This is what I found on php.net. Same thing in a handy function.

          function get_include_contents($filename) {
            if (is_file($filename)) {
              ob_start();
                include $filename;
                $contents = ob_get_contents();
                ob_end_clean();
                return $contents;
            }
            return false;
          }
          
          $output = get_include_contents("assets/snippets/somesnippet/somsnippet.main.php");
          
          return $output;
          
            • 10153
            • 138 Posts
            Quote from: Mark at Aug 26, 2005, 12:28 PM

            Yeah. Just use a template containing only my GrabPage snippet and then you can avoid copying and pasting.

            Where can I find more information on Grabpage ? Etosite is down for now...
            Thanks
              Be not deceived: evil communications corrupt good manners.
              I Corinthians (ch. XV, v. 33)
              • 30095
              • 9 Posts
              Great tip!! so I can include in modx any kind of code without difficoult.
                • 21255
                • 215 Posts
                By the way, if you have snippets that should die under certain conditions, you can improve your debugging process by using the logEvent API function:

                // Example
                if(!is_set($needed_variable)) {
                  $error_message = "[".$modx->getSnippetName()."] The following error occured while processing document ".$modx->documentIdentifier.": \n";
                  $error_message.= "Your error message goes here.";
                  $modx->Event->alert($error_message);
                  $modx->logEvent(0, 3, $error_message, $modx->getSnippetName());
                  return "<!-- ".$modx->getSnippetName()." failed -->";
                }
                


                This helps you identifying the error by inserting the the DocID where the custom error occured into event log, and it will leave a mark in the html-source of you document.
                  • 32241
                  • 1,495 Posts
                  That’s a nice tip netnoise.

                  Thanks for the info, I never thought of that.
                    Wendy Novianto
                    [font=Verdana]PT DJAMOER Technology Media
                    [font=Verdana]Xituz Media
                    • 31211
                    • 25 Posts
                    This technique can be used with templates and chunks?
                      • 28042 ☆ A M B ☆
                      • 24,524 Posts
                      Yes, you can use a simple snippet to include your external file as the only content of a template or a chunk. Although I don’t think there’s much point in doing it with a chunk, since for the most part they are intended to be small bits of HTML and text, like footer content, that wouldn’t really much benefit from being in an external file.

                      Consider that MODx first has to go to the database to get the content of the chunk, then eval() the snippet’s php code, which in turn goes to the filesystem to get the external file. Kind of a lot of overhead for a couple of lines of text. But you have to weigh the cost/benefit and decide when it’s worth the overhead to make life more convenient.
                        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