We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 7455
    • 2,204 Posts
    Is it possible to truncate the introtext field? I like to use this field instead of the content field because the contentfield has html tags and classes that I do not want to have/use in my ditto output. so introtext would be the best option but i do not want people to have the option to keep on tpying. but I like to truncate this field.

    Greets Dimmy
      follow me on twitter: @dimmy01
      • 18397
      • 3,250 Posts
      Not at the moment. However, in the next release it is.
        • 27376
        • 576 Posts
        Make a plugin that uses the [tt]OnBeforeDocFormSave[/tt] event and truncate the [tt]$introtext[/tt] variable.

        <?php
        /**
         * Truncate Intro Text Plugin
         *
         * @author Matthew Pietz <[email protected]>
         * @version 0.1b
         * @see http://modxcms.com/forums/index.php/topic,12001.0.html
         *
         * Events Selected: OnBeforeDocFormSave
         */
        global $introtext; // the variable to truncate
        
        $maxlength = 120; // set this to whatever length you want.
        
        $introtext = strip_tags($introtext); // get rid of html tags
        
        $introtext = substr($introtext, 0, $maxlength);
        
        // This can definitely be expanded to stop at a word break or something (by searching for spaces at or near $maxlength) but maybe in a later version.
        


        There’s something I just whipped in 3 minutes. Untested of course, but it seems right judging by my knowledge of the core smiley

        Keep in mind this is a server-side truncation, so the editors will have no knowledge of what is truncated until after it’s saved.
          • 7455
          • 2,204 Posts
          Nice sirlancelot, thanks for the plugin code and Mark looking forward to the next release I love ditto.
            follow me on twitter: @dimmy01
            • 10534
            • 40 Posts
            I’ve been wanting a bit of the same... I’ve created a multilingual website; with a method I havent seen here:
            created a new TV "content_en". I’ve put the regular [*content*] in a div with class "bla~nl" and [*content_en*] in a div with class "bla~en". With link extra css will be loaded and a cookie will be set to set the language: one of the divs will be hidden and the other will be visible. I’ve done the same with all other content, e.g. menutitle, etc.

            Now, next item: Ditto & the summary extender. How can I add functionality so that I can truncate the english content in de blogview as well? [+summary+] uses summary and content. I leave summary purpusfully empty so that the content is truncated. For the english view I want the TV content_en to be shown and truncated ([+content_en+] is not trunctated as this is not caught by summary-extender). Could I duclicate the summary extender and rename all right the functions?? How could I fix this?

            thnx!
              • 10534
              • 40 Posts
              Noone has a solution for this? sad
                • 33372
                • 1,611 Posts
                Er... I’m not sure if I understand what you’re trying to do, because it doesn’t seem like it should be difficult at all to me. All you want to do is to truncate the output text in a Ditto call?

                One way that seems like it would be easy to do this would be to write a simple snippet that returns the introtext of each document truncated to whatever length you want in the Ditto call, e.g.
                [[truncateIntrotext? &docID=`[+id+]` &length=`120`]]

                I can’t see any reason this wouldn’t work, but perhaps I’m not understanding what you’re trying to do?
                  "Things are not what they appear to be; nor are they otherwise." - Buddha

                  "Well, gee, Buddha - that wasn&#39;t very helpful..." - ZAP

                  Useful MODx links: documentation | wiki | forum guidelines | bugs & requests | info you should include with your post | commercial support options
                  • 28042 ☆ A M B ☆
                  • 24,524 Posts
                  I’ve used PHx to do this when I wanted a one-liner for a home page box, but a full intro for the main subject page.
                    Studying MODX in the desert - http://sottwell.com
                    Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
                    Join the Slack Community - http://modx.org