I use the DataObjectManager module to enable the admin to upload multiple images. My .ss template then displays each image.
I want to display a count if images with each image, like this:
<img scr="image.jpg" alt="image" />Image 1 of 3
<img scr="image.jpg" alt="image" />Image 2 of 3
<img scr="image.jpg" alt="image" />Image 3 of 3
<?php
class CarouselImage extends DataObject {
static $db = array (
'Caption' => 'Varchar(200)'
);
static $has_one = array (
'Image'=>'Image',
'Parent'=>'SiteTree'
);
/**
* Gets the fields for the cms
* @return {FieldSet} Field set for use in the popup
*/
public function getCMSFields_forPopup() {
$fileField=new FileIFrameField('Image');
$fileField->setAllowedExtensions(array('jpg','gif','png'));
$fields=new FieldSet(
$fileField,
new TextField('Caption','Caption',$this->Caption,200),
new HiddenField('ParentIDCache','ParentIDCache',$this->getParentIndex())
);
return $fields;
}
/**
* Forces the parent id before calling the parent's onBeforeWrite
*/
public function onBeforeWrite() {
if(!isset($this->record['ParentIDCache'])) {
$pId=array_values($this->toMap());
$this->record['ParentID']=$pId[2];
}else {
$this->ParentID=$this->record['ParentIDCache'];
}
parent::onBeforeWrite();
}
/**
* Gets the parent index of the data object
* @return {int} Page's internal ID
*/
private function getParentIndex() {
$pId=array_values($this->toMap());
if(isset($this->ParentID) && $this->ParentID!=null && $this->ParentID!=0) {
return $this->ParentID;
}else {
return $pId[1];
}
}
}
?>
Here is code from my .ss template
<% control CarouselImages %>
<img src="$Image.URL" alt="$Caption.ATT" />
<% end_control %