We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 19328
    • 433 Posts
    Just a quick copy-n-paste tip for the MODX beginner. As you might know, you can't have multiple values in the stripString output modifiers. Here is a solution: create a custom output modifier. This way you can have a strip command with multiple values to strip.

    Create a snippet (name: stripWords) with this code, and alter to your needs:
    $string = $input;
    $output = str_replace(array('these', 'words', 'will', 'be', 'stripped'), '' , $string);
    return $output;


    And call it in your tag: [[*content:stripWords]]

    Good luck!

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

      • 3749
      • 24,544 Posts
      Very nice! smiley

      Here's a version with the words to strip in the tag (untested):

      [[*content:stripWords=`these,words,will,be,stripped`]]



      /* stripWords snippet */
      $words = array_map('trim', explode(',', $options));
      return str_replace($words, '', $input);


      michelle84's version will be faster.

      If you often change the words to be stripped, you might want to just put them in a chunk:

      wordsToStrip chunk:

      these,words,will,be,stripped



      /* stripWords snippet */
      $words = $modx->getChunk('wordsToStrip');
      $words = array_map('trim', explode(',', $words));
      return str_replace($words, '', $input);


      Note that you can replace the '' with something to put in place of the stripped words:


      return str_replace($words, '[expletive deleted]', $input);







      [ed. note: BobRay last edited this post 8 years, 11 months ago.]
        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
        • 3749
        • 24,544 Posts
        Just a note. This would be much faster if you could do the replacements when the document is saved using a plugin, though it often wouldn't be practical. AFAIK, it wouldn't work with Articles or their comments, for example.

        It would be slightly faster to do it in a plugin attached to the OnWebPagePrerender System Event.
          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
          • 19328
          • 433 Posts
          Thanks for the complement Bob!
          • discuss.answer
            • 3749
            • 24,544 Posts
            You're welcome. I managed to get a blog post out of this (with credit to you, of course). smiley
              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