I have an odd gallery implementation, so I've decided to use the ImageDataObjectManager.
I've added it to Page.php so I could have a separate gallery for each page. It seems to be working when I look at the CMS (it's only showing the images I've uploaded for that specific page). But when viewing the site, every page is outputting all photos that were added no matter what page they were uploaded to.
Thanks
GalleryPhoto.php
class GalleryPhoto extends DataObject {
static $db = array (
'Category' => 'Varchar',
'PhotoCredit' => 'Varchar(200)'
);
static $has_one = array (
'Attachment' => 'File',
'Page' => 'Page'
);
public function getCMSFields_forPopup()
{
return new FieldSet(
new TextField('Category'),
new TextField('PhotoCredit'),
new FileIFrameField('Attachment')
);
}
}
Page.php
static $has_many = array (
'PhotoGallery' => 'GalleryPhoto'
);
...
function Lightbox() {
return DataObject::get('GalleryPhoto');
}
Page.ss
<% control Lightbox %>
$Attachment
<% end_control %>