Jump to:

17452 Posts in 4473 Topics by 1971 members

Archive

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: 2234 Views
  • sd0wn
    Avatar
    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?

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

  • Anatol
    Avatar
    126 Posts

    Re: LatestNews vs. Article Holder Link to this post

    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

  • BLU42 Media
    Avatar
    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:

    $Content.FirstParagraph
    $Content.FirstSentence

    Check out http://doc.silverstripe.com/doku.php?id=htmltext for more details.

    Hope that helps!

    2234 Views
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.