We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 24374
    • 322 Posts
    After converting a site to 2.3, the number '1' is appearing after every single spot in the pages that has a snippet! Weird. Here's a screen shot:



    What's going on???
      • 27708 MODX Staff
      • 2,502 Posts
      Do you have custom snippets that are using echo() vs return()?
        Author of zero books. Formerly of many strange things. Pairs well with meats. Conversations are magical experiences. He's dangerous around code but a markup magician. Blog ✦ Twitter ✦ LinkedIn ✦ GitHub
        • 27708 MODX Staff
        • 2,502 Posts
          Author of zero books. Formerly of many strange things. Pairs well with meats. Conversations are magical experiences. He's dangerous around code but a markup magician. Blog ✦ Twitter ✦ LinkedIn ✦ GitHub
          • 24374
          • 322 Posts
          Quote from: smashingred at Jul 17, 2014, 09:41 AM
          Do you have custom snippets that are using echo() vs return()?
          Yes! That never caused a problem before. But, here's the thing. If I have several places in a script that create output, if I use "return", the rest of the script doesn't run, and that causes havoc. To have to rewrite ALL my scripts so that all output is delayed until the very end of the script would be a nightmare.
            • 24374
            • 322 Posts
            OK, it seems if I just put

            return '';

            at the end of every script, all is well.
              • 27708 MODX Staff
              • 2,502 Posts
              MODX Snippets are not quite like regular PHP scripts but rather, they behave like functions and must return some output, see: http://rtfm.modx.com/revolution/2.x/developing-in-modx/basic-development/snippets/how-to-write-a-good-snippet#HowtoWriteaGoodSnippet-DonotPrint
                Author of zero books. Formerly of many strange things. Pairs well with meats. Conversations are magical experiences. He's dangerous around code but a markup magician. Blog ✦ Twitter ✦ LinkedIn ✦ GitHub
                • 24374
                • 322 Posts
                But MODX is supposed to be about creative freedom! smiley

                And a confession:
                I DO mix HTML in some snippets, because there are cases where it's simply too cumbersome not too, and taking the time to split every single bit of HTML off into a chunk is not time-efficient. I know we're not "supposed" to do this, but it works, and it saves time for my clients.
                  • 27708 MODX Staff
                  • 2,502 Posts
                  I don't mean to mix issues or best practices. For the return() part there is a functional reason to use it vs the best practices for making distributable and more maintainable Extras. I absolutely support the pragmatic choice of choosing to incorporate output HTML within the context of the script if it's a) not going to be reused or shared and b) means the project will get done faster. So what you're supposed to do for clients and what you're supposed to do so your snippets always work are 2 different things.
                  :)
                    Author of zero books. Formerly of many strange things. Pairs well with meats. Conversations are magical experiences. He's dangerous around code but a markup magician. Blog ✦ Twitter ✦ LinkedIn ✦ GitHub
                    • 28042 ☆ A M B ☆
                    • 24,524 Posts
                    On this same line, I've noticed quite a lot of messages in the error log from plugins returning a 1. Ace, for one, returns a 1 for every time OnDocFormRender is invoked. Which can be quite a lot.
                      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