Quote from: frogabog at Aug 06, 2012, 11:41 PM
The bandaid fix is to make sure to fill out the introtext field. However, for SEO purposes, and for when an end user changes the first few sentences, remembering to duplicate the changes in the introtext field isn't going to happen. Ideally it should just use the first 200 characters and leave it at that, whatever those characters are.
The only way to do that that I can think of is to write your own custom modifier that strips out MODX tags from the output, truncates it, and use the custom modifier instead of the limit modifier.
I think this would do it (modified from code at
http://rtfm.modx.com/display/revolution20/Custom+Output+Filter+Examples)):
<?php
$output = '';
$options = !empty($options)?$options:50;
if (!empty($input) && !empty($options)) {
if (strlen($input) > $options) {
$input = preg_replace('/\x20*\[\[.*\]\]\x20*/', ' ', $input);
$input = preg_replace(
$output = substr($input, 0, strrpos(substr($input, 0, $options), ' '));
}
else{
$output = $input;
}
}
return $output;
Create a snippet called mylimit with the code above and use just :mylimit after the striptags modifier. It defaults to 50 characters but you can use mylimit=`200` and it has the advantage of not truncating words.
The new preg_replace was trickier than I expected. It replaces MODX tags and any spaces before and after them with a single space. Let me know if it works and I'll post it on the custom modifier page.
BTW, I don't think there is a perfect solution. What you're trying to do isn't going to help much when a user forgets to update the introtext field, because it still may not be empty.
------------------------------------------------------------------------------------------
PLEASE, PLEASE specify the version of MODX you are using.
MODX info for everyone:
http://bobsguides.com/modx.html
[ed. note: BobRay last edited this post 14 years, 1 month ago.]