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
www.9thwave.co.uk
WEB | DESIGN | PRINT
-
☆ A M B ☆
- 24,524 Posts
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, 9 months ago.]
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
-
☆ A M B ☆
- 24,524 Posts
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."
discuss.answer
-
☆ A M B ☆
- 24,524 Posts
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();
}
Thanks very much Sottwell, that worked a treat.:-)
www.9thwave.co.uk
WEB | DESIGN | PRINT