Hi,
I am building my first website with SilverStripe and came across the following problem.
One of my template needs to be associated with a list of images that would be uploaded and managed via the CMS.
I used an HasManyComplexTableField as following to add and manage images:
class projectPage extends Page
{
static $db = array
(
.....
);
static $has_one = array
(
);
static $has_many = array
(
'Images' => 'ProjectImage'
);
function getCMSFields()
{
$fields = parent::getCMSFields();
.....
$tablefield = new HasManyComplexTableField(
$this,
'Images',
'ProjectImage',
array(
'Title' => 'Image Title'
),
'getCMSFields_forPopup'
);
$tablefield->setAddTitle( 'an Image' );
$fields->addFieldToTab( 'Root.Content.Images', $tablefield );
return $fields;
}
}
Here is the ProjectImage class:
class ProjectImage extends DataObject
{
static $db = array
(
'Title' => 'Varchar'
);
static $has_one = array
(
'Project' => 'projectPage',
'Image' => 'Image'
);
function getCMSFields_forPopup()
{
$fields = new FieldSet();
$fields->push( new TextField( 'Title' ) );
$fields->push( new ImageField( 'Image' ) );
return $fields;
}
}
This all works quite OK, I manage to display the list of images back on the page via <% control Images %> but I can't get it to display the images themselves. The $Title works fine on the other hand.
I tried using $Images, $Images.URL or $URL, but nothing seem to work. If someone could help me with that, it would be much appreciated.
Also, I was wondering some little things, to make this all work and look better....
Is it possible to add a preview of the picture within the HasManyComplexTableField on the CMS page? I tried to add the Image object to the field list of the table, but this makes the all thing crash.
Is it also possible to "link" the list of images to only one page (the one where they have been added from) rather than linked to the Page Type. So far if a new page is created, this page will also display the list of images added on any other pages (this can be messy to manage if for example, each projectPage contain 10+ images and there is 20+ projectPages...)
Maybe this is not the best way to achieve what I am trying to do. And I would be happy to hear any better solution.
I know this might be a lot to ask all at once, and I hope it all make sense.
Thanks for you help - Thierry