Hi Larry!
That's easy. First, you'll need to create a new class based on DataObject with your two fields: Image and URL
<?php
class MyLinkedImage extends DataObject {
public static $db = array(
"URL" => "Text"
);
public static $has_one = array(
"Image" => "Image",
"Homepage" => "HomePage"
);
public function getCMSFields_forPopup() {
return parent::getCMSFields();
}
}
?>
Rename the class MyLinkedImage to anything you like and name the file the same way. Now download ImageDataObjectManager (you will find the module DataObjectManager on silverstripe.org) and install it. It will help you to manage your DataObjects. Now tell your (maybe newly created) HomePage.php to "have many" of these images:
<?php
class HomePage extends Page {
// ...
public static $has_many = array(
"Image" => "MyLinkedImage"
);
public function getCMSFields() {
$f = parent::getCMSFields();
$f->addFieldToTab("Root.Content.Image", new ImageDataObjectManager(
$this,
'Image',
'Image',
'Image',
array(
'URL' => 'URL'
),
'getCMSFields_forPopup'
)
);
return $f;
}
// ...
}
?>
Here you'll find the docs for DataObjectManager
Later, you display them by just adding this to your template:
<% control MyLinkedImage %>
<a href="$URL">$Image</a>
<% end_control %>
This will display all images at once. If you want to display on a a time randomly, you will need to add some logic - but that should be easy ;)
Greetings!
craesh