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

If more than 3 images in control


Go to End
Reply


2 Posts   923 Views

Avatar
DeklinKelly

Community Member, 197 Posts

29 June 2009 at 5:34am

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

Avatar
Willr

Forum Moderator, 5517 Posts

29 June 2009 at 5:56pm

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();
}