We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 40389
    • 8 Posts
    using Revo version 2.2.4-pl
    using PHP 5.2.17

    The following code in a snippet returns the text "Home", while I would expect 'home":
    The name of the snippet is "pagetitle_to_lower"

    (please ignore / and \ around the brackets, can't get to show my thing without - is there a trick to that to)

    $str = "[[*pagetitle]]";
    $str1 = strtolower($str);
    return $str1;


    I am calling the shippet with [\[pagetitle_to_lower]] on my rescource.
    What am I doing wrong?
    I know a work-around /[\[*pagetitle:lcase]], but I would like to know what I am doing wrong in the snippet - the snippet(s) seem to work, for example reversing the function strrev() works fine. [ed. note: smashingred last edited this post 14 years, 2 months ago.]
      • 28042 ☆ A M B ☆
      • 24,524 Posts
      (please ignore / and \ around the brackets, can't get to show my thing without - is there a trick to that to)
      Put code samples in code tags, use the <> icon in the post editing toolbar.

      Anyway, your problem may be related to the encoding of the string. Some PHP string functions don't do well with unicode encoding. See http://www.php.net/manual/en/function.mb-strtolower.php
        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
        • 3749
        • 24,544 Posts
        First of all, you can't use MODX tags in PHP code. PHP doesn't know what they are. Your snippet is actually returning the string with the tag in it, which MODX renders as usual.

        If you wanted to use a snippet, you'd have to pass the pagetitle as a property to the snippet or have the snippet get the pagetitle directly like this:

        <?php
        return strtolower($modx->resource->get('pagetitle'));
        



        but it would be a lot more convenient to just use this the existing lcase output modifier: wink


        [[*pagetitle:lcase]]



        ------------------------------------------------------------------------------------------
        PLEASE, PLEASE specify the version of MODX you are using.
        MODX info for everyone: http://bobsguides.com/modx.html
          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
          • 40389
          • 8 Posts
          Thank you Susan and Bob - just learned 2 things smiley