Yeah, that's really easy to do with DOM. In this example, I'll assume you want to upload your own thumbnail rather than letting Silverstripe generate it for you..
PortfolioPage.php
class PortfolioPage extends Page
{
static $has_many = array (
'PortfolioItems' => 'PortfolioItem'
);
public function getCMSFields() {
$f = parent::getCMSFields();
$f->addFieldToTab("Root.Content.Portfolio Items", new ImageDataObjectManager($this,'PortfolioItems','PortfolioItem','Thumbnail'));
return $f;
}
}
class PortfolioPage_Controller extends Page_Controller
{
public function show()
{
if($this->urlParams['ID'] && is_numeric($this->urlParams['ID'])) {
return array (
'PortfolioItem' => DataObject::get_by_id("PortfolioItem", $this->urlParams['ID']
);
}
return false;
}
}
PortfolioItem.php
class PortfolioItem extends DataObject
{
static $db = array (
'Title' => 'Text',
'Caption' => 'Text'
);
static $has_one = array (
'PortfolioPage' => 'PortfolioPage',
'Thumbnail' => 'Image',
'FullSize' => 'Image'
);
static $summary_fields = array (
'Title' => 'Title',
'Caption' => 'Caption'
);
public function getCMSFields()
{
return new FieldSet(
new TextField('Title'),
new TextareaField('Caption'),
new ImageField('Thumbnail'),
new ImageField('FullSize','Full size image')
);
}
public function Link()
{
return Controller::join_links($this->PortfolioPage()->Link(),'show',$this->ID);
}
}
PortfolioPage.ss
<ul>
<% control PortfolioItems %>
<li><a href="$Link">$Thumbnail.SetWidth(200)</a>
<a href="$Link">$Title</a> $Caption</li>
<% end_control %>
</ul>
PortfolioPage_show.ss
<% if PortfolioItem %>
<% control PortfolioItem %>
<h2>$Title</h2>
<p>$Caption</p>
<div>$FullSize.SetWidth(500)</div>
<% end_control %>
<% else %>
That portfolio item was not found.
<% end_if %>
Might be some syntax errors in there, but that's what you get for a 90-second code sprint. :)
Enjoy.