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

Randomizing Custom Content


Go to End


3 Posts   1523 Views

Avatar
Enclave

Community Member, 4 Posts

12 September 2008 at 9:24pm

Hi Guys

I had a look at some of the posts on random content but nothing really answers what I would like to do.

I created 4 new fields in the db and cms for my HomePage.php page model. Showcase1-4. I have added content to Showcase1-4 and call them as $Showcase1, $Showcase2 in my view. I would like to randomize the actual content being shown ie only one showcase between $Showcase1 and $Showcase4 should be shown at any one time.

Is this possible?

Any help would be greatly appreciated.

Avatar
Phalkunz

Community Member, 69 Posts

13 September 2008 at 12:15am

In your home page controller:

function randShowcase() {
   $random = rand(1, 4);
   $field = 'Showcase'.$random;
   return $this->$field;
}

so in your template you can call $randShowcase

Avatar
Enclave

Community Member, 4 Posts

13 September 2008 at 1:42am

Thanks! Much appreciated.