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

    I’m sure there’s a simple answer to this question but I’ve been searching forums and Googling it for quite a while and haven’t found any clues yet.

    I’m new to ModX and am using Revolution.

    Trying to create a simple snippet that will take a string value and give me the lower case of it (to get class names, image names, etc from my page titles).

    This is my snippet (I tried using echo and return):
    <?php
    echo strtolower($value);
    ?>

    It works ok when I do something like this:
    [[LowerCase? &value=`Mixed Capitals ARE Bad`]]

    But trying to pass in another value (from within WayFinder here, but anything dynamic) like this:
    [[LowerCase? &value=`[[+wf.title]]`]]

    just refuses to transform the string to lower case! It gets the correct title value but outputs it as is, not in lowercase. It’s driving me nuts!

    Is this the right way to accomplish what I want to do? Am I missing something silly?

    Thanks for your help.
      • 3749
      • 24,544 Posts
      This won’t satisfy your curiosity, but the PHX plugin should solve your problem. wink

      Evolution:
      [+wf.title:lcase+]


      Revolution:
      [[+wf.title:lcase]]
        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
        • 4172
        • 5,888 Posts
        don’t know why your snippet doesn’t work
        return strtolower($value);

        should do it.

        But Bob is right with phx.
        Since you are in Revo, there are output-filters, which you can use and it has to be:

        [[+wf.title:lcase]]

        [[+wf.title:lowercase]]

        [[+wf.title:strtolower]]


        see http://svn.modxcms.com/docs/display/revolution/Input+and+Output+Filters
          -------------------------------

          you can buy me a beer, if you like MIGX

          http://webcmsolutions.de/migx.html

          Thanks!
          • 3749
          • 24,544 Posts
          Oops. Didn’t notice that the OP was in Revolution (where PHX is built in). Post edited.

          Sorry for any confusion.
            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
            • 14368
            • 56 Posts
            Thanks for the advice, sounds like filters would be perfect.
            Unfortunately I still can’t get it to work.

            This is my RowTpl chunk for WayFinder:

            <li><a id="mu[[+wf.title:lcase]]" href="[[+wf.link]]" title="[[+wf.title]]"><span>[[+wf.title]]</span></a></li>

            But the value output into the source is ’id="mu"’ with no titles at all - let alone lower case ones. If I leave out the :lcase filter then the titles come through ok, but they disappear when using :lcase, :lowercase, or :strtolower.
              • 22303 MODX Staff
              • 10,725 Posts
              As a filter, lcase is built-in and should just work. If you are providing your own snippet using a different name, it would need to be:
              <?php
              return strtolower($input);
              ?>
                • 14368
                • 56 Posts
                Thanks, that’s what I thought too but I can’t get either method to work. I also just upgraded to Revo rc2 in the hopes that that would fix it, but I’m still having the same problems.

                Here is my WayFinder chunk that uses filters:
                <li><a id="mu[[+wf.title:lcase]]" href="[[+wf.link]]" title="[[+wf.title]]"><span>[[+wf.title]]</span></a></li>


                This outputs
                <li><a id="mu" href="http://<removed>.com.au/modx/" title="Home"><span>Home</span></a></li>



                Here is the same chunk using my LowerCase snippet:
                <li><a id="mu[[LowerCase? &input=`[[+wf.title]]`]]" href="[[+wf.link]]" title="[[+wf.title]]"><span>[[+wf.title]]</span></a></li>


                This outputs:
                <li><a id="muHome" href="http://<removed>.com.au/modx/" title="Home"><span>Home</span></a></li>


                LowerCase Snippet is:
                <?php
                return strtolower($input);
                ?>


                Feel like I’m going crazy. I like the ideas in MODx but having trouble with such a basic task is getting me a bit frustrated ...
                  • 14368
                  • 56 Posts
                  Still trying to nut this out, found something that may be interesting ...

                  I’ve been going back to using my LowerCase snippet in an attempt to figure out what’s happening.
                  Thought I’d see if I could get other PHP functions to work, so tried this just to see what happened:

                  <?php
                  //return strtolower($input);
                  return strtolower($input) . '|' . strlen($input) . '|' . strtoupper($input) . '|' . strrev($input);
                  ?>


                  And got some very funny-looking output ...
                  <li><a id="muHome|13||]]eltit.fw+eltit.fw+eltit.fw+eltit.fw+eltit.fw+[[" href="index.php?id=5" title="Contact"><span>Contact</span></a></li> 


                  Seems like the first use of $input (strtolower) retrieves the first wf.title, but does not transform it to lowercase.
                  The second use (strlen) retrieves the length of [[+wf.title]], NOT the length of the real value (e.g. Home, Contact, etc).
                  The third use (strtoupper) just gives a blank value.
                  The fourth use (strrev) seems to be reversing the string ’[[+wf.title+wf.title+wf.title+wf.title+wf.title]]’ which is really strange as it looks to have repeated ’+wf.title’ for each of my menu items. Huh??

                  Someone please tell me what I am doing that’s so horribly wrong ...
                    • 14368
                    • 56 Posts
                    The LowerCase snippet does what I expect it to when used outside of WayFinder, so I think these are both WayFinder issues (the output filtering not working, and funny behaviour of my snippet).
                    I’ve created a post over in that section at http://modxcms.com/forums/index.php/topic,49924.0.html. Still looking into it and would appreciate any tips.
                      • 22303 MODX Staff
                      • 10,725 Posts
                      Agreed this seems to be an issue with Wayfinder and should be fixed there. Thanks for not giving up in frustration.