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.

DataObjectManager Module /

Discuss the DataObjectManager module, and the related ImageGallery module.

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

Limiting Results of Control


Go to End


4 Posts   1588 Views

Avatar
VictorH

Community Member, 29 Posts

24 February 2010 at 4:19pm

Edited: 24/02/2010 4:20pm

I have the following code that displays all the posters belonging to the Movie Page. I'm using the same code on the Homepage as I'm using a specific function to pull in the Movie pages on the homepage. On the homepage I want to limit the number of posters to 4. I can't seem to do this any help?

<ul class="movieList">
		<% control MoviePages %>
			<li>
				<h2><a href="$Link">$Title<% if MovieVersion %> <span>($MovieVersion)</span><% end_if %></a></h2>
				<% if ReleaseDate %><p><strong>Release Date:</strong> $ReleaseDate.Nice</p><% end_if %>
				<h3>Sypnosis</h3>
				$Content				
				<h3>Posters</h3>
				<% if Posters %>
					<ul class="posters clear">
						<% control Posters(4) %>
							<li>
								<a href="<% control PosterImage %>$URL<% end_control %>" title="$Pos/$TotalItems - $PosterName" rel="$MoviePage.Title"><% control PosterImage %><img src="<% control CroppedImage(125,188) %>$URL<% end_control %>" alt="$Title Poster Thumbnail" width="<% control CroppedImage(125,188) %>$Width<% end_control %>" height="<% control CroppedImage(125,188) %>$Height<% end_control %>" /><% end_control %><span></span></a>
							</li>
						<% end_control %>
					</ul>
				<% else %>
					<h5>No Posters Yet</h5>
					<p>Do you have a poster for this movie? Please <a href="contact">send it to us</a> so we can add it to the site.</p>
				<% end_if %>
			</li>
		<% end_control %>
	</ul>

Avatar
UncleCheese

Forum Moderator, 4102 Posts

24 February 2010 at 4:39pm

You just need to write a custom getter..

function HomePosters()
{
return $this->Posters(null, null, null, 4);
}

Avatar
VictorH

Community Member, 29 Posts

24 February 2010 at 4:53pm

I tried doing this:
Homepage.php

function MoviePosters() {
		$doSet = DataObject::get(
			$callerClass = "Poster",
			$filter = "`MoviePageID` = '".$this->ID."'",
			$sort = "Sort DESC",
			$join = "",
			$limit = "0,4"
		);
		return $doSet ? $doSet : false;
	}

Homepage.ss
<% control MoviePosters %>
					test
				<% end_control %>

It doesn't produce anything.

Avatar
UncleCheese

Forum Moderator, 4102 Posts

24 February 2010 at 5:42pm

         $filter = "`MoviePageID` = '".$this->ID."'",

MoviePages are associated with your homepage? Seems odd.