21301 Posts in 5735 Topics by 2603 members
| Go to End | ||
| Author | Topic: | 535 Views |
-
Re: Get Random Image

1 November 2012 at 5:57am
You don't need to extend the Page_Controller. Just put it in your SiteConfigCustom class
class SiteConfigCustom extends DataExtension {
public function getRandomImage() {
return $this->BackgroundImages()->sort('RAND()')->First();
}}
and as far as i know, in your template file (Page.ss) you have to put the $ sign when using <% loop %>
<% loop $SiteConfig %>
<% end_loop %>
It may not work without the $.
-
Re: Get Random Image

1 November 2012 at 6:04am
If I put it up there, it breaks and I get the blank white page of death.
I don't believe the $ is necessary unless your doing something like <% if $MyDinner="kipper" %>
-
Re: Get Random Image

1 November 2012 at 6:17am
oh, made a silly mistake...it should be
public function getRandomImage() {
return $this->owner->BackgroundImages()->sort('RAND()')->First();
}need the "owner" part when your in a DataExtension
. I think that might fix it. -
Re: Get Random Image

1 November 2012 at 6:30am
That seems to work with this change to the template:
Page.ss
<% loop SiteConfig %>
$RandomImage.BackgroundImage
<% end_loop %>Thanks to all!
-
Re: Get Random Image

1 November 2012 at 6:34am
oh that's right. Good call on the template.
you could also use
<% loop SiteConfig.RandomImage %>
$BackgroundImage
<% end_loop %>if you wanted to loop through more then one random image.
| 535 Views | ||
| Go to Top |


