Jump to:

23376 Posts in 18214 Topics by 2867 members

General Questions

SilverStripe Forums » General Questions » If more than 3 images in control

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

Page: 1
Go to End
Author Topic: 778 Views
  • DeklinKelly
    Avatar
    Community Member
    197 Posts

    If more than 3 images in control Link to this post

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

  • Willr
    Avatar
    Forum Moderator
    5489 Posts

    Re: If more than 3 images in control Link to this post

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

    778 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.