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

Looping through a lot of images


Go to End


6 Posts   1049 Views

Avatar
Kimyeti

Community Member, 7 Posts

24 September 2016 at 1:31am

Hi

I'm fairly new to Silverstripe so I apologize for a newbie question, but I can't seem to figure out how to loop many images on my website.

Do I need to create a function or dataobject or something like that? Here is the code:

http://i.imgur.com/B29xNBc.png

http://i.imgur.com/IDt233A.png

I appriciate the help.

Avatar
LoFonz

Community Member, 12 Posts

5 October 2016 at 9:32am

Yop!

<% loop CarouselImages %>
<img src="<% $Image.CroppedImage(..., ...).Url %>" alt="" />
<% end_loop %>

should work, but I haven't played with Silverstripe for a while (will get back into in tomorrow since I need it :D) so just give it a try and tell me if it works :).

Avatar
Faloude

Community Member, 55 Posts

10 October 2016 at 1:33am

Your code looks just fine. Did you do a ?flush=all just in case?

Also, in which PageType class did you write the back-end code (getCMSFields etc)? And in which front-end template are you fetching the items?

It should be in the same scope. Writing the code in HomePage.php and fetching in Contact.ss for example would require some extra code afaik.

Avatar
Kimyeti

Community Member, 7 Posts

11 October 2016 at 6:51am

Edited: 11/10/2016 6:52am

Hi

Thank you for your anwers.

LoFonz:

I have tried it with your example, but it does not work. Nothing apperas just like my own code.

Faloude:

I have flushed like a mad-man but it does not help at all. The PageType class is called "ServicePage.php" like so:


<?php
class ServicePage extends Page {

private static $db = array(

);

private static $has_one = array(
'SummaryImage' => 'Image'
);

private static $has_many = array(

);

private static $many_many = array(
'CarouselImages' => 'Image'
);

public function getCMSFields(){
$fields = parent::getCMSFields();
$fields->addFieldToTab('Root.Carousel', UploadField::create('CarouselImages', 'Carousel pictures'));

return $fields;
}

}
class ServicePage_Controller extends Page_Controller {

}

The SS file should be in the same scope. It is called "ServicePage.ss".

Do you guys have any other suggestions to what is wrong? I'm out of ideas :P Thanks again.

Avatar
Faloude

Community Member, 55 Posts

11 October 2016 at 7:15am

Edited: 11/10/2016 7:16am

Remove CarouselImages within the loop like so:

<a href="$CroppedImage(1000,600).URL">

Avatar
Kimyeti

Community Member, 7 Posts

31 October 2016 at 11:46pm

Faloude :

I completely forgot to reply - my apologies. You were right! Thank you very much :)