Jump to:

3373 Posts in 998 Topics by 712 members

Data Model Questions

SilverStripe Forums » Data Model Questions » how to show the last 3 pages from the specified section

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

Page: 1
Go to End
Author Topic: 922 Views
  • fiord
    Avatar
    Community Member
    79 Posts

    how to show the last 3 pages from the specified section Link to this post

    I have several sections like NewsHolder
    On my MainPage I want to show grups of the las 3 children page

    3 Latest News From NewsHolder [1]
    -NewsPageName [Last]
    -NewsPageName [Last-1]
    -NewsPageName [Last-2]

    3 Latest News From NewsHolder [2]
    -NewsPageName [Last]
    -NewsPageName [Last-1]
    -NewsPageName [Last-2]

    3 Latest News From NewsHolder [3]
    -NewsPageName [Last]
    -NewsPageName [Last-1]
    -NewsPageName [Last-2]

    on the forum I found a function for my MainPage

    function NewsList($num=3, $ParentURL='news') {
       $news = DataObject::get_one("NewsHolder", "URLSegment = '$ParentURL'");
       return ($news) ? DataObject::get("NewsPage", "ParentID = $news->ID", "Date DESC", "", $num) : false;
    }

    but it does not work when I sets $ParentURL

       <% control NewsList(3, $NewsHolder1URL) %>
          <div class="newsBl2">
             <div class="date">$Date.Nice</div>
             <a href="$Link" title="$Title.XML" class="newsH"><img src="img/newsHead/{$ID}.png" alt="$Title.XML" /></a>
             <div class="NewsDesc">$NewsDesc </div>
          </div>
       <% end_control %>


    I have next Error

    Parse error: syntax error, unexpected '}' in C:\Users\vitaliy\AppData\Local\Temp\silverstripe-cacheV--home-p.org.ua-www-harley-davidson\.cacheV..home.p.org.ua.www.harley-davidson.themes.harley.templates.Layout.MainPage.ss on line 197

    What am I doing wrong?

  • Sam
    Avatar
    Administrator
    679 Posts

    Re: how to show the last 3 pages from the specified section Link to this post

    You can't put a $ reference in the control. The template language doesn't work that way.

    Instead, update NewsList() to refer to $this->NewsHolder1URL and then do away with the 2nd argument altogether.

  • fiord
    Avatar
    Community Member
    79 Posts

    Re: how to show the last 3 pages from the specified section Link to this post

    great thanks
    I thought that I will dance all night with timbrel

    922 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.