We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 36549
    • 572 Posts
    Does anyone know if there is a way to recreate the Ditto property "&truncAt"?
    I was using in blog posts to truncate the content at a particular point like this: "&truncAt=`+END_SUMMARY+`"

    Thanks for any pointers

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

      www.9thwave.co.uk
         WEB | DESIGN | PRINT
    • I think you would need to create a custom output filter.

      This should do the job, name a snippet "stopAt"
      $result = $input;
      if ( true === isset($stopAt) ) {
      	$result = substr($result,0,strrpos($input,$stopAt));
      }
      return $result;


      Then use the output modifier in your getResources tpl [[+content:stopAt=`--My_String--`]]

      [ed. note: sottwell last edited this post 9 years ago.]
        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
        • 36549
        • 572 Posts
        Hi Sottwell, thank you for taking a look at this.
        I have create the snippet and added [[+content:stopAt=`+END_SUMMARY+`]] (with '+END_SUMMARY+' being the text within each resource's content area) but it still displays the whole post.
        I suppose ideally i want that bit of text removed completely from the post and then I can use `ellipsis` to limit the characters.
        Do you know if it's possible to remove the string '+END_SUMMARY+' from the content with PHP?
          www.9thwave.co.uk
             WEB | DESIGN | PRINT
        • It's certainly possible.

          $content = str_replace('+END_SUMMARY+', ' ', $content)
          


          That line of code will replace the '+END_SUMMARY+' with a space. You would need to loop through your resources and apply that line of code to each resource. Something like this should do the job. Just put it in a snippet in a page (I always have an unpublished "testing" page to do things like this), and open the page in your browser to run the snippet.

          USE AT YOUR OWN RISK - BACKUP YOUR DATABASE BEFORE TRYING THIS!!!

          $resources = $modx->getIterator('modResource');
          foreach($resources as $resource) {
            $content = $resource->get('content');
            $content = str_replace('+END_SUMMARY+', ' ', $content);
            $resource->setContent($content);
            $resource->save();
          }
          return "Done."
          
            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
          • discuss.answer
            Well, it works for me without the return statement.
            $resources = $modx->getIterator('modResource');
            foreach($resources as $resource) {
              $content = $resource->get('content');
              $content = str_replace('+END_SUMMARY+', ' ', $content);
              $resource->setContent($content);
              $resource->save();
            }
              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
              • 36549
              • 572 Posts
              Thanks very much Sottwell, that worked a treat.:-)
                www.9thwave.co.uk
                   WEB | DESIGN | PRINT