Jump to:

17452 Posts in 4473 Topics by 1971 members


SilverStripe Forums » Archive » LatestNews vs. Article Holder

Our old forums are still available as a read-only archive.

Moderators: martimiz, Sean, biapar, Willr, Ingo, simon_w

Page: 1
Go to End
Author Topic: 2245 Views
  • sd0wn
    Community Member
    2 Posts

    LatestNews vs. Article Holder Link to this post

    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">&nbsp;</div><% end_if %>
    <% end_control %>

  • Anatol
    126 Posts

    Re: LatestNews vs. Article Holder Link to this post


    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.


    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


  • BLU42 Media
    Community Member
    71 Posts

    Re: LatestNews vs. Article Holder Link to this post

    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!

Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.