Hi All,
I'm working on a site in Silverstripe 2.4.4
I've got a bit of a complex holding page to build which draws various information from its children in the site tree, and also has some interspersed random images.
In the page template itself, I have the following (snipped a bit to remove irrelevant junk):
<% control Children %>
<div class="foreground" id="fore$ID">
<img class="galleryseat" src="/themes/blackcandy/images/bench.png" alt=""/>
<img class="galleryobject" src="$Top.randomObject" alt=""/>
</div>
<% end_control %>
Obviously $Top.randomObject is the function which selects a random image from one of the directories in the site. It is defined in the page controller :
class GalleryMainPage_Controller extends ContentController {
public static $allowed_actions = array (
);
public function randomObject() {
//selects a random object from the pool and adds it to the page
$randImg = DataObject::get_one("Image", "ParentID = 30", false, "RAND()" );
return $randImg->Filename;
}
}
Now, the function is working correctly and returns a random image from the specified directory, but the problem I am getting is that the image does not change with each loop in the Children control... so I end up with multiple copies of the same random image (if that makes sense !)
I was hoping this would be a simple little function... Have I completely missed the point ? :-)
Any pointers appreciated.
Cheers
Tim