We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 36446
    • 184 Posts
    Hi Guys!
    I instantly installed modx 2.3 and it worked without problems but i am facing a strange problem since the update. I have 2 very simple snippets that i have created myself. The first is a user greetings snippet and the second one is the CheckUser Snippet that i found here in the forums.
    Snippet greeting:
    <?php
    $HourOfDay = '<script type="text/javascript">
    var jetzt = new Date();
    var x = jetzt.getHours();
    if (x < 12) {
        greeting = "Good morning";
    } else if (x < 20) {
        greeting = "Good afternoon";
    } else {
        greeting = "Good evening";
    }
    document.write(greeting)
    </script>';
    echo $HourOfDay;

    Snippet CheckUser:
    <?php
    /* CheckStatus snippet */
    if (! $modx->user->hasSessionContext('web') ) {
        $modx->sendRedirect($modx->makeUrl(34));
    }


    The Snippets both still work. Here are my snippet calls:
    [[!greeting?]] and
    [[!CheckUser?]] like it was done bevore the update.

    Now these snippets return the value that they are ment to but add a "1" at the end. So my greeting looks like this:
    Goog morning1 Username... I do not understand why this happens. Can anyone help? Thanks a bunch!
    Sven

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

    [ed. note: smashingred last edited this post 9 years, 9 months ago.]
      https://www.beautyislife-shop.de - premium make-up!
      https://www.topsterne.de - sell it here!
      ---------------------------------------------------------
    • discuss.answer
      Snippets should never echo, they should always return. Actually, a snippet will return in any case, but as you see, now if you don't give it something to return it will return 1 for success.

      return $HourOfDay;
        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
        • 36446
        • 184 Posts
        Quote from: sottwell at Jul 16, 2014, 09:09 AM
        Snippets should never echo, they should always return. Actually, a snippet will return in any case, but as you see, now if you don't give it something to return it will return 1 for success.

        return $HourOfDay;

        Hi Susan!
        Thank you very much! I just figured it out! Now it is working! Thanks a ton! but why did it work in modx 2.2?
          https://www.beautyislife-shop.de - premium make-up!
          https://www.topsterne.de - sell it here!
          ---------------------------------------------------------
          • 33337
          • 3,975 Posts
          It would be great if OP can edit and prefix the topic title with [Solved].
            Zaigham R - MODX Professional | Skype | Email | Twitter

            Digging the interwebs for #MODX gems and bringing it to you. modx.link
          • @zaigham, and OP, I've changed the thread to a Question and selected @sottwell's answer as the solution.
              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. BlogTwitterLinkedInGitHub