17452 Posts in 4473 Topics by 1971 members
|Go to End|
22 July 2008 at 5:12am
Is there anyway to limit the amount of characters returned for the $Content?
I like how the News displays on the article holder page, but for sidebar (latest news) on the homepage, I dont want to display so much. Maybe 120 characters max.
Is this possible?
function LatestNewsItems($num = 3)
$news = DataObject::get_one("ArticleHolder");
return ($news) ? DataObject::get("ArticlePage", "ParentID = $news->ID", "Date DESC", "", $num) : false;
<% control LatestNewsItems %>
<% if FirstLast != last %><div class="hr"> </div><% end_if %>
<% end_control %>
22 July 2008 at 11:48am Last edited: 22 July 2008 11:49am
That's probably what you are looking for. You can limit the number of characters, or the number of words, display the first paragraph only, etc...
Just add e.g.
You can also change the default characters that are displayed at the end if the text exceeds the maximum length (default is '...'). See here: http://api.silverstripe.com/sapphire/model/Text.html#methodLimitCharacters
22 July 2008 at 11:50am
You sure can... easily too! There are some cool functions built right into the framework that you can use in your ss template. Just switch out $Content with one of these:
Check out http://doc.silverstripe.com/doku.php?id=htmltext for more details.
Hope that helps!
|Go to Top|