Jump to:

23478 Posts in 18941 Topics by 2878 members

General Questions

SilverStripe Forums » General Questions » What do I need and how do I do this on Silverstripe?

General questions about getting started with SilverStripe that don't fit in any of the categories above.

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

Page: 1
Go to End
Author Topic: 507 Views
  • Lemonie
    Community Member
    70 Posts

    What do I need and how do I do this on Silverstripe? Link to this post

    I am still trying to learn how to do things on Silverstripe but the hardest thing when you are teaching yourself is what you need to ask for!?

    I want to create pages with articles/news items on as shown in this link ...


    ... say 5 pages and then a main page with feeds on as shown in this link ...


    I have absolutely no idea where to start!! Please could you point me in the right direction and keep it simple, I am in the early stages of the learning process

  • Johan
    Community Member
    49 Posts

    Re: What do I need and how do I do this on Silverstripe? Link to this post

    It's so easy when you know how. The problem I also find with SilverStripe is finding the information, especially if you are not a programmer or part of the team.

    Presuming you are using SS3 and you added your news articles to the CMS page with a date, I create a news template with...

    static $db = array(
          'Date' => 'Date'

    and a nice way to show the date in the CMS...

       function getCMSFields() {
          $fields = parent::getCMSFields();   
             $datefield = new DateField('Date', 'Publication date');
             $datefield->setConfig('showcalendar', true);
             $datefield->setConfig('showdropdown', true);
             $datefield->setConfig('dateformat', 'dd/MM/YYYY');            
             $fields->addFieldToTab('Root.Main', $datefield, 'Content');


    You need to display snippets from the page above in the tree then create a template called NewsHolder simply in the SS file template add...

    <% loop Children %>

    <div class="date">
    <p>$Content.FirstParagraph </p>
    <p><a href="$Link" class="more">Read more</a></p>

    <% end_loop %>

    ..but if you want to diplay snippets on another template like the homepage you need to create a function I call it LatestNews function and call this from the SS. The function will call the NewsHolder you created above.

    <% loop LatestNews %>
    <div class="news-item jlink">
    <p><span class="date">$Date.Nice</span><br>
    <a class="more" href="$Link">Read more</a> - $Content.FirstSentence</p>
    <% end_loop %>

    ...and the function you need goes is the PHP of the template in the mysite/code such as hompage.php inside the class HomePage extends Page {...

       // show news
       function LatestNews($num=2) {
          $news = DataObject::get_one("NewsHolder");
          return ($news) ? DataObject::get("NewsArticle", "ParentID = $news->ID", "Date DESC", "", $num) : false;

    That should be more than enough to get you going if not go back to the basic tutorials. Good luck.

    p.s. I would re-write the topic title to explain the content of the posts so that others know what this thread is about.

  • stallain
    Community Member
    61 Posts

    Re: What do I need and how do I do this on Silverstripe? Link to this post


    The query is even easier to write since SS3 :

    function LatestNews() {
    return NewsArticle::get()->sort('Date','DESC')->limit(2);

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.