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.

General Questions /

General questions about getting started with SilverStripe that don't fit in any of the categories above.

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

If more than 3 images in control


Go to End


2 Posts   1130 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, 5523 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();
}