Hi,
I'm trying to figure out how to call in the first image for a page with one of my template .ss files. The images are associated with the page via $many_many.
Here is mysite/code/CasePage.php:
class CasePage extends Page {
private static $db = array (
'Intro' => 'Text'
);
private static $many_many = array (
'Photos' => 'Image'
);
public function getCMSFields() {
$fields = parent::getCMSFields();
$fields->addFieldToTab('Root.Main', TextareaField::create('Intro','The introduction for the page'),'Content');
$photos = new UploadField('Photos', 'Photos for this case study', $this->Photos());
$fields->addFieldToTab('Root.Photos', $photos);
$photos
->setFolderName('case-study-photos')
->getValidator()->setAllowedExtensions(array('jpg', 'jpeg', 'png'));
return $fields;
}
}
class CasePage_Controller extends Page_Controller {
}
And I've got a loop for the photos in my .ss file (see below), but I actually just want to call in the first image, and have a SetWidth(550) applied to it. The below calls in all the images, but doesn't work if I change $URL to $URL.SetWidth(550). This is for a holder page that lists a load of case studies, and so for each case study on this page, I'm just wanting to show the first image from a bunch that the client will associate with that case study.
Please help! :)
<% if $Photos %>
<figure class="media">
<% loop $Photos %>
<img src="$URL" alt="$Title" title="$Title" width="$Width" height="$Height">
<% end_loop %>
</figure>
<% end_if %>