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

    I am using MODx 2.0.7. Is there any way to make the :ellpsis or :limit output filter not truncate words? Or do I need a custom filter for that?

    Thanks
    Martin
      • 21838
      • 284 Posts
      Hey,

      I don’t know why this is not a default output filter as it’s a very nice enhancement.
      So you have to create your own output filter (or better use a snippet instead which is faster):

      create a snippet "cutWordsTags":
      <?php
      $output = '';
        $input = strip_tags($input,'<p><br><br /><a>');
      if (!empty($input) && !empty($options)) { 
        if (strlen($input) > $options) {
               $output = substr($input, 0, strrpos(substr($input, 0, $options), ' '));
        } else $output = $input;
      }
      return $output.' (…)'; // sorry please change here with ' and semicolon​ the and sharp 38 semicolon is not intended and inserted by forum?
      

      and call it via:
      [[cutWordsNoTags? &input=`[[+content]]` &options=`750`]]
      

        MODX Free Template Base: MODX-Boilerplate | my blog (lots of MODX stuff) | my gitHub (translations) | MODX User Groups Germany (Facebook)
        • 10313
        • 375 Posts
        Thank you, that works very fine. I changed it a little bit and posted it to the official MODx documentaion.

        I named it "shorten", gave it a default output length and omitted the strip_tags, because there is already the :stripTags filter.
          • 11076
          • 159 Posts
            Michael Shraibman( gOmp)  | Freelance Design & Development | wink  impossible is nothing...
            • 10313
            • 375 Posts
            Thanks, gOmp! I didn’t know it was "your" code smiley
              • 11076
              • 159 Posts
              hi, i really don’t care ’bout the credit ,just recognized it. We’re here to share and if it comes handy to somebody then great smiley it’s the main purpose, especially with this simple tiny code.

              BTW, you can achive this also with only revo’s built-in filters but you’ll need to cascade 3 of them, which takes a little bit more time to execute i think.
                Michael Shraibman( gOmp)  | Freelance Design & Development | wink  impossible is nothing...
                • 8872
                • 41 Posts
                Quote from: gOmp at Feb 01, 2011, 09:17 AM

                BTW, you can achive this also with only revo’s built-in filters but you’ll need to cascade 3 of them, which takes a little bit more time to execute i think.

                How to do that, I am more interested in that approach?