Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We're retiring the forums!

The SilverStripe forums have passed their heyday. They'll stick around, but will be read only. We'd encourage you to get involved in the community via the following channels instead:

Archive /

Our old forums are still available as a read-only archive.

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo

silverstriping a site with random pictures


Go to End


22 Posts   9923 Views

Avatar
stooni

Community Member, 89 Posts

21 August 2008 at 2:41am

Hello imback, i bring the image in the sidebar hugh!!!

but i cant render image with the gd i have think i can get these in Sidebar.ss

<img src="$RandomImage(gallery)" width="$resizeByWidth(150) " alt="$Title photo" />

it's not working any other ideas!!

Thanks

--Stooni

Avatar
Fuzz10

Community Member, 791 Posts

21 August 2008 at 4:46am

Please have a good look at the tutorials / docs , it explains quite a bit about the Image type.

Avatar
ben123

Community Member, 4 Posts

22 October 2008 at 11:23pm

Hi,

I'm trying to do this too - I think I've followed through the steps suggested above, but it doesn't seem to be finding the function.

Have put:

function RandomImage( $strLeftDirName )
{
if ( !is_string( $strLeftDirName ) )
{
return false;
}
$left_dir = DataObject::get_one("Folder", "Name = \"$strLeftDirName\"");
$randImg = ( $left_dir->ID ) ? DataObject::get_one("Image", "ParentID = $left_dir->ID", true, "RAND()" ) : false;
return $randImg->Filename;
}

function init() {
parent::init();

Requirements::themedCSS("style");

}

in Page.php, and have put:

<img src="$RandomImage(assets/Uploads)" />

in Page.ss.

I'm just getting:

<img src="" >

No error message... what am I missing?

thanks,

Ben

Avatar
stooni

Community Member, 89 Posts

23 October 2008 at 7:37pm

Edited: 23/10/2008 7:38pm

Hello i have in the Page.php

function RandomImage( $strLeftDirName )
{
if ( !is_string( $strLeftDirName ) )
{
return false;
}
//$strLeftDirName2 = $strLeftDirName."\\_resampled\\";
$left_dir = DataObject::get_one("Folder", "Name = \"$strLeftDirName\"");

$randImg = ( $left_dir->ID ) ? DataObject::get_one("Image", "ParentID = $left_dir->ID", true, "RAND()" ) : false;
//resize(25,35);
return $randImg-> Filename;
}

in the function :class Page_Controller extends ContentController !

and in the Sidebar.ss, at the end!

<a href="bilder/" ><img src="$RandomImage(foldername)" width="150" alt="$Title photo" /></a></p>

i hope you can do it ! here the url from the projekt website http://www.nree.ch/

Avatar
ben123

Community Member, 4 Posts

25 October 2008 at 7:33am

Thanks Stooni.
Still couldn't work it out!?! - but have gone with a different solution now.

Avatar
JoeJoe

Community Member, 8 Posts

3 November 2008 at 7:30am

I've also the same problem with creating a thumbnail.

I use;

 

class ProjectHolder_Controller extends Page_Controller {
	 function randomProject() {
		$imageField = DataObject::get_one('ProjectPage', "", "", 'RAND()');
		return $imageField;
	} 
}

And in my Template i use:

 $randomProject.Photo1 

Simply $randomProject.Photo1.SetWidth(100); is not possible. Is there a solution to create a thumbnail ?

Go to Top