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.

General Questions

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

If more than 3 images in control


2 Posts   798 Views


29 June 2009 at 5:34am Community Member, 197 Posts

This displays all images in a control:

<% control CarouselImages %>
<img src="$Image.URL" alt="$Caption.ATT" />
<% end_control %>

But I only want to do a conditional to check if there are more than 3 images:

<% if CarouselImages >3 %>
<h1>There are more than three images!</h1>
<% end_if %>


29 June 2009 at 5:56pm Forum Moderator, 5511 Posts

You cannot do that in the templates. You would need to write a snippet of PHP

function Carousel() {
if($this->CarouselImages()) { if($this->CarouselImages()->TotalItems() > 3) return "Too Many"; }
return $this->CarouselImages();