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 have a small snippet that works pretty well, I use it to truncate my "summary" fields (the snippet call is in a chunk - for my frontpage news)

    And I realize that it might serve other people and be available to download in snippet section.

    The only thing I do not understand is that during a call, if special characters such as "?" or ":" is in my field summary the snippet completely bug

    Does anyone could help me?

    Here is the snippet + the call I use:
     [[truncate? &what=`[+summary+]` &len=`700`]]


    <?php
    /* ----------
    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;
    ?>
      Scuse my english...I&#39;m swiss
      • 629
      • 2 Posts
      Thank you. It’s work wery well and it’s easy to use.
        Andy Greco
        • 16034
        • 107 Posts
        The parser can not handle special characters in the snippet arguments.

        You could do this with PHx: http://wiki.modxcms.com/index.php/PHx/CustomModifiers#phx:character_limit
          MODx snippet-glossary 101:
          Ditto = Content Lister -- Wayfinder == Menu Builder -- Jot = Comment Control