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.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

Data Model Questions /

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

how to show the last 3 pages from the specified section


Go to End


3 Posts   1751 Views

Avatar
WebSpilka

Community Member, 89 Posts

24 February 2009 at 6:48am

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?

Avatar
Sam

Administrator, 690 Posts

24 February 2009 at 8:53am

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.

Avatar
WebSpilka

Community Member, 89 Posts

24 February 2009 at 10:01am

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