17488 Posts in 4473 Topics by 1978 members
|
Page:
1
|
Go to End | |
| Author | Topic: | 2031 Views |
-
LatestNews vs. Article Holder

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?
Page.php:
function LatestNewsItems($num = 3)
{
$news = DataObject::get_one("ArticleHolder");
return ($news) ? DataObject::get("ArticlePage", "ParentID = $news->ID", "Date DESC", "", $num) : false;
}LatestNews.ss
<% control LatestNewsItems %>
<p>$Content</p>
<% if FirstLast != last %><div class="hr"> </div><% end_if %>
<% end_control %> -
Re: LatestNews vs. Article Holder

22 July 2008 at 11:48am Last edited: 22 July 2008 11:49am
Hi,
try this page: http://doc.silverstripe.com/doku.php?id=text&s=limitcharacters
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.
$Content.LimitCharacters(120)
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
Cheers!
Anatol -
Re: LatestNews vs. Article Holder

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:
$Content.FirstParagraph
$Content.FirstSentenceCheck out http://doc.silverstripe.com/doku.php?id=htmltext for more details.
Hope that helps!
| 2031 Views | ||
|
Page:
1
|
Go to Top |


