Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

Data Model Questions

how to show the last 3 pages from the specified section


3 Posts   984 Views


24 February 2009 at 6:48am Community Member, 79 Posts

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>
   <% end_control %>

I have next Error

Parse error: syntax error, unexpected '}' in C:\Users\vitaliy\AppData\Local\Temp\\ on line 197

What am I doing wrong?


24 February 2009 at 8:53am Administrator, 685 Posts

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.


24 February 2009 at 10:01am Community Member, 79 Posts

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