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

Answered Strange Snippets

    • 50146
    • 5 Posts
    Wherever I use any [[snippet]] I recieve "1" number in the output html. Even if the snippet code is empty I get that bug. I cant get my head around it what is it. Any ideas? smiley

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

    [ed. note: deadcatbounce last edited this post 11 years, 6 months ago.]
      • 50146
      • 5 Posts
      Debug mode shows nothing.
        • 46886
        • 1,154 Posts
        Removed [ed. note: nuan88 last edited this post 11 years, 6 months ago.]
          • 4172
          • 5,888 Posts
          which MODX - version?

            -------------------------------

            you can buy me a beer, if you like MIGX

            http://webcmsolutions.de/migx.html

            Thanks!
            • 50146
            • 5 Posts
            Quote from: nuan88 at Mar 26, 2015, 02:30 AM
            How about if the snippet is called uncached, [[!snippet]]?
            Same story.



            Quote from: Bruno17 at Mar 26, 2015, 02:39 AM
            which MODX - version?

            It was 2.3.0, but no any result after update to the latest version.
              • 28042 ☆ A M B ☆
              • 24,524 Posts
              Is this a custom snippet? What does the final return directive of the snippet look like?
                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
              • discuss.answer
                • 3749
                • 24,544 Posts
                When a snippet doesn't have a return value, PHP returns true (1) to indicate that it executed successfully. MODX replaces all snippet tags with the return value of the snippet. That's why you're seeing a 1.


                Putting this at the end of the snippet will prevent that, but don't do it for snippets that already return a meaningful value:

                return '';


                If these are your own snippets, it sounds like you are producing the output with echo or print. You should do this instead:

                $output = '';
                
                $output = 'whatever you want to output';
                $output .= 'Something more to add to the output';
                // etc.
                
                return $output;
                  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
                  • 50146
                  • 5 Posts
                  Quote from: BobRay at Mar 26, 2015, 11:06 PM

                  Putting this at the end of the snippet will prevent that, but don't do it for snippets that already return a meaningful value:
                  This is it! Thanks