3214 Posts in 848 Topics by 810 members
|
Page:
1
|
Go to End | |
| Author | Topic: | 260 Views |
-
Looping Over Images In A Specific Folder

30 December 2012 at 2:11am
I have been over numerous portions of the documentation and still cannot find an answer to this specific question:
I have one page template which will be used for multiple (different) subjects with corresponding (by subject) images. Each subject will have its own nested page. I want to organize the images into different folders by subject (Images/Subject1, Images/Subject2, etc.) , and then display the individuals images in the nested page by looping over them in their particular folder. How and where would I specify the particular folder to loop from, as I am also guessing this will be based on which nested page is currently active.
Question: How exactly would this loop be written and how would the particular folder and path be specified based on the "current" nested page?
Many thanks in advance!
-
Re: Looping Over Images In A Specific Folder

10 January 2013 at 8:07pm
You may want to do all 5 tutorials if you haven't done them yet as they'll contain the tools you need to achieve this.
First you create your page type for your custom page, on this page type you set up a has_one relationship to a 'folder' and add a TreeDropdownField to allow you to select the folder in the CMS.
class MyPageType extends Page {
public static $has_one = array(
'ImagesFolder' => 'Folder'
);public function getCMSFields() {
$fields = parent::getCMSFields();
$fields->addFieldToTable('Root.Content.Main', new TreeDropdownField('ImagesFolderID'));
}
}Then after running dev/build you can select the folder in the CMS backend. To select the images from that folder you can add another function to that class
function getUploadedImages() {
return ($this->ImagesFolderID) ? DataObject::get('Image', "ParentID = '$this->ImagesFolderID'") : false;
}Then use <% control UploadedImages %>... <% end_control %> to loop the images.
* Note you may run into syntax errors
| 260 Views | ||
|
Page:
1
|
Go to Top |


