3214 Posts in 848 Topics by 810 members
| Go to End | ||
| Author | Topic: | 5047 Views |
-
Re: NoHTML in LimitWordCount Summary

14 December 2010 at 8:07pm
u can add given below function to ur "sapphire/core/model/fieldtypes/Text.php
function CustomWordCount($numWords = 30, $add = '...') {
$this->value = strip_tags($this->value);
$ret = explode(' ', $this->value, $numWords + 1);if(count($ret) <= $numWords - 1) {
$ret = $this->value;
} else {
array_pop($ret);
$ret = implode(' ', $ret) . $add;
}
return $ret;
}and then in .ss file call,
$Content.CustomWordCounti hope it will work for u.
-
Re: NoHTML in LimitWordCount Summary

14 January 2011 at 12:06am Last edited: 14 January 2011 12:08am
This is new I think.
I see this in "sapphire/core/model/fieldtypes/Text.php"
/**
* Limit this field's content by a number of words.
* CAUTION: This is not XML safe. Please use
* {@link LimitWordCountXML()} instead.
*
* @param int $numWords Number of words to limit by
* @param string $add Ellipsis to add to the end of truncated string
* @return string
*/
function LimitWordCount($numWords = 26, $add = '...') {
$this->value = trim(Convert::xml2raw($this->value));
$ret = explode(' ', $this->value, $numWords + 1);
if(count($ret) <= $numWords - 1) {
$ret = $this->value;
} else {
array_pop($ret);
$ret = implode(' ', $ret) . $add;
}
return $ret;
}So add $Content.LimitWordCount to the .ss file for 26 words or add $Content.LimitWordCount(10) to change the amount of words.
| 5047 Views | ||
| Go to Top |


