Login | Forgot password | Register

X

What is OpenID?

OpenID is an Internet-wide identity system that allows you to sign in to many websites with a single account.

With OpenID, your ID becomes a URL (e.g. http://username.myopenid.com/). You can get a free OpenID for example from myopenid.com.

For more information visit the official OpenID site.

Jump to:

17480 Posts in 4474 Topics by 1973 members

Archive

SilverStripe Forums » Archive » Randomizing Custom Content

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

Page: 1
Go to End
Author Topic: Randomizing Custom Content 532 Views
  • Enclave
    avatar
    Community Member
    4 posts

    Randomizing Custom Content Link to this post

    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.

  • Phalkunz
    avatar
    63 posts

    Re: Randomizing Custom Content Link to this post

    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

  • Enclave
    avatar
    Community Member
    4 posts

    Re: Randomizing Custom Content Link to this post

    Thanks! Much appreciated.

    532 Views
Page: 1
Go to Top

Currently Online: JoshuaLewis, NickJacobs

Welcome to our latest member: marcusl

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.