We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 34026
    • 10 Posts
    If I use this:
    [[+content:ellipsis=`300`:stripTags]]
    words are being cut off.

    MODX Community Foru...

    Is there a way to have it not cut off words but keep words in one piece.

    MODX Community Forums...



      • 1343 ☆ A M B ☆
      • 2,213 Posts
      I would suggest putting stripTags first, otherwise you can end up with "<br " where you might not want it. As for eliminating cutoff words, I think you would need to build something custom.

      Hope that helps.
        Patrick | Server Wrangler
        About Me: Website | Tweets |  MODX Hosting
        • 3749
        • 24,544 Posts
        You could create your own custom output modifier. Something like this (untested):

        [[+content:striptags:ellipsis=`300`:WholeWords]]


        <?php
        /* WholeWords snippet */
        
        $pos = strrpos($input, ' ');
        return substr($input, 0, $pos);
          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
          • 34026
          • 10 Posts
          Thanks Bob,

          It works! I replaced ellipsis with limit and used your snippet.

          [[+content:striptags:limit=`300`:WholeWords]]
            • 3749
            • 24,544 Posts
            I'm glad to hear it worked. 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
              • 27106
              • 147 Posts
              Brilliant solution.

              AMDbuilder's warning to use the striptags modifier seems important too, though I notice from trial-and-error that paragraph tags get closed automatically. Does anyone know how important it is to use striptags i.e. how badly you can break your page without it? And is the behaviour of the ellipsis and limit modifiers fully documented anywhere?
                David Walker
                Principal, Shorewalker DMS
                Phone: 03 8899 7790
                Mobile: 0407 133 020
                • 3749
                • 24,544 Posts
                It really depends on what's in the selected section (the part up to the limit). If you don't use striptags at all, you can end up with an unclosed <div>, <img>, or <a href> tag that will either mess up the rest of the page or make it disappear when the browser tries to interpret the rest of the page as a URL.

                If you use striptags, it's important to put it first because otherwise, a) the length of the return string will be unreliable because the tag characters will be counted and b) if a start tag is in the selection and its closing tag isn't, striptags can eat the rest of your content looking for it.

                As for the behavior of the two functions, the limit modifier simply counts all characters and returns the string up to the number you specify. The ellipsis modifier does exactly the same thing and then appends '&#8230;' ('…') before returning the string.
                  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