We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 45118
    • 123 Posts
    When I use wordwrapcut it adds an space at the beginning of the second line.
    [[+abc]] is a placeholder for a field containing 9 digit numbers with a suffix separated with a dash. For example ABC123456-7.0
    <div>[[+abc:wordwrapcut=`9`]]</div>

    This renders the following:
    <div>ABC123456<br />
     -7.0</div>

    Is there anyway I can achieve the same result without the extra space?

    Thank you!

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

      • 42562
      • 1,145 Posts
      I don't know if there is an already-made alternative.

      But with https://rtfm.modx.com/revolution/2.x/making-sites-with-modx/customizing-content/input-and-output-filters-(output-modifiers)/custom-output-filter-examples you can easily cook one up.

      With some PHP substring + explode etc, you should be celebrating.

      If I write a working example before you do, I'll share it.
        TinymceWrapper: Complete back/frontend content solution.
        Harden your MODX site by passwording your three main folders: core, manager, connectors and renaming your assets (thank me later!)
        5 ways to sniff / hack your own sites; even with renamed/hidden folders, burst them all up, to see how secure you are not.
      • discuss.answer
        • 42562
        • 1,145 Posts
        http://php.net/substr_replace
        Okay, here we go.

        Create a snippet, myWordwrapcut
        $string = substr_replace($input, '<br />', $options, 0);
        return $string;

        Test with this
        <div>[[+abc:myWordwrapcut=`9`]]</div>
          TinymceWrapper: Complete back/frontend content solution.
          Harden your MODX site by passwording your three main folders: core, manager, connectors and renaming your assets (thank me later!)
          5 ways to sniff / hack your own sites; even with renamed/hidden folders, burst them all up, to see how secure you are not.
          • 3749
          • 24,544 Posts
          I think this would also work:

          return str_replace('-', '<br  />', $input;)


          I would call it hyphenToBr.
            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
            • 45118
            • 123 Posts
            Quote from: donshakespeare at Sep 02, 2015, 02:21 PM
            http://php.net/substr_replace
            Okay, here we go.

            Create a snippet, myWordwrapcut
            $string = substr_replace($input, '<br />', $options, 0);
            return $string;

            Test with this
            <div>[[+abc:myWordwrapcut=`9`]]</div>

            Thanks, this works!
            But there's one issue with doing it this way. Not all my numbers have suffixes (for example some numbers are just like this ABC123456) and all of them are getting a break tag whether they need it or not, like this:
            <div>ABC123456<br />-7.0</div>
            and
            <div>ABC123456<br /></div>
            .

            However, your example showed me how to make a custom output filter and I came up with this:
            Snippet myWordwrapcut
            $string = wordwrap($input, $options, '<br />', true);
            return $string;

            Code in the chunk is the same
            <div>[[+abc:myWordwrapcut=`9`]]</div>

            This renders the numbers as follows:
            <div>ABC123456<br />-7.0</div>
            and
            <div>ABC123456</div>


            Perfect!
            Now when I search on the page I can find the number ABC123456-7.0 without any trouble, while before it would only find ABC123456 -7.0 (with a space before the dash).

            Thanks again for your help, it's very much appreciated.
              • 45118
              • 123 Posts
              Quote from: BobRay at Sep 03, 2015, 01:15 AM
              I think this would also work:

              return str_replace('-', '<br>', $input;)


              I would call it hyphenToBr.

              Hi Bob, thanks for your input, but I don't want the dash replaced, just the extra space gone.
                • 42562
                • 1,145 Posts
                Glad it all got fixed.
                  TinymceWrapper: Complete back/frontend content solution.
                  Harden your MODX site by passwording your three main folders: core, manager, connectors and renaming your assets (thank me later!)
                  5 ways to sniff / hack your own sites; even with renamed/hidden folders, burst them all up, to see how secure you are not.
                  • 3749
                  • 24,544 Posts
                  In that case, it would be:

                  return str_replace('-', '<br  />-', $input;)
                    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