We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 53177
    • 14 Posts
    I've been trying to find an answer to this question, and it seems like there should be a simple 'output modifier' solution.

    I want to use a page's pagetitle as a body class, however, I can't seem to find an easy way to strip out all non-alphanumeric characters besides underscores or hyphens.

    Ideally, I want to replace all spaces with dashes, and remove anything else (that isn't a letter or number).

    How do I do this? There doesn't seem to be a string output modifier that I can use to accomplish this seemingly simple task.
      • 3749
      • 24,544 Posts
      How about using the alias instead of the pagetitle? It could still contain numbers, but numbers are acceptable in class names as long as the first character is a letter.
        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
        • 53177
        • 14 Posts
        Quote from: BobRay at Jan 25, 2018, 07:04 AM
        How about using the alias instead of the pagetitle? It could still contain numbers, but numbers are acceptable in class names as long as the first character is a letter.

        Actually that's a decent idea. Not sure why I didn't think of it. Though I found, I had to add some characters to the Friendly URL filter in setup to clean it a bit more (commas, exclamation marks, brackets are all still allowed by default).

        But that use-case aside ... do you know of a snippet that would sanitize text to strip out all but alpha numerics? I found some examples online, but they didn't work for me (I'm not a programmer, so I wasn't sure what I was doing wrong).

        Thanks for your response, Bob! I very much appreciate it.

          • 52064
          • 120 Posts
          create a snippet sanitize

          <?php
          return preg_replace('/[^a-z0-9]/', '', strtolower($input));
          


          call on title page
          [[*pagetitle:sanitize]]
          


            FerX - Developer at Eracom s.r.l.