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

    I’m searching how to trunc a introtext [+summary+] from a chunk like this:


    <div id="tpl-image-div2"><img src="[+tvimage_220-170+]" width="220" height="170" align="left" /> </div>
    <div id="tpl-image-div3"><a href="[~[+id+]~]">[+title+]</a></div>
    <div id="tpl-image-div4">[+tvauteur_n1+], le [+date+]</div>
    <div id="tpl-image-div5"> [+summary+]... </div>
    </div>


    I’ve tried with PHx, Ditto (&truncOffset, &truncLen) - no luck !

    My ditto call:
    [!Ditto? &tpl=`tpl-menu-image` &parents=`41` &display=`1` &extenders=`summary` &trunc=`true` &truncOffset=`15` &truncLen=`120`!]

    Does anybody have a solution or a snippet call that work ?

    Thanks for you help
    Mehdi
      Scuse my english...I&#39;m swiss
      • 1122
      • 209 Posts
      I don’t think that Ditto has an ability to truncate/shorten its placeholders. The shortest way (not necessarily simpliest) is a creation of your own snippet to handle such a shortening. Here goes an idea of such a snippet. Suppose, we name it "truncate", its code may look like:
      /* ----------
      parameters:
      $what - text to shorten
      $len - desired length of the shortened text
         ---------- */
      if (strlen($what) > $len) {
        /* there is a point to truncate */
        $what = preg_replace('/^(.{' . $len . ',}? ).*$/is', '$1', $what) . '...';
      }
      return $what;
      

      Then the part of your template relating to [+summary+] should look like:
      <div id="tpl-image-div5">[[truncate? &what=`[+summary+]` &len=`80`]]</div>
      

      The above-presented code of the snippet is merely an idea of it. The shortening is done via regular expression that takes at least $len characters (80 in an example) and truncates at the first space met.
        • 19036
        • 119 Posts
        Whououu ! Oh thanks a lot for you help Alik - it works really well....! wink

        Kind Regards,
        Mehdi
          Scuse my english...I&#39;m swiss
          • 7231
          • 4,205 Posts
          Another alternative would be to use ditto’s built in PHx features to truncate the field. Here is some info on PHx:
          http://wiki.modxcms.com/index.php/PHx

          You can use PHx in a Ditto Tpl by setting &phx=`1` in the Ditto call:
          http://ditto.modxcms.com/files/snippet-ditto-php.html#phx
            [font=Verdana]Shane Sponagle | [wiki] Snippet Call Anatomy | MODx Developer Blog | [nettuts] Working With a Content Management Framework: MODx

            Something is happening here, but you don&#39;t know what it is.
            Do you, Mr. Jones? - [bob dylan]
            • 30394
            • 7 Posts
            Thank you, Alik.

            Saved me some extra work. Appreciate it.
              • 8790
              • 526 Posts
              hi,

              this truncate snippet is cool, but his should not be necessary as Ditto is supposed to be able to truncate into its summary pl , but it seams absolutely out of order ( however its doc is clear: http://ditto.modxcms.com/extenders/summary.html )
                Schtroumpf Grognon - Grouchy Smurf
                ---------------------------------
                Faites pas attention.. - Don&#39;t pay attention
                http://www.dzi-neo.net