Is there a way to randomly display multiple INTRO texts?

I am using <?= $page->intro()->kirbytext() ?> to display a short “intro to my work” text on my site home page. Let’s say the intro text is “I build houses”. I’d like to be able to randomly display two more intro texts in the same location on the site (one at a time). The intro text should change upon page load. So “I build houses” changes to “I build cars” changes to “I build bikes” when the page is reloaded. I have found some jQuery/Javascript which looks like it would fit the bill (http://jsfiddle.net/JZDnv/) but I am wondering if this could be done directly in Kirby? Thanks in advance for any ideas you might have.

Kurt

Let’s say you store these intro texts in a structure field called intros:

Blueprint:

fields:
  intros:
    type: structure
    fields:
      intro:
        type: textarea

Then you would get a random entry like this:

$introTexts = $page->intros()->toStructure();
$randomItem= $introTexts->shuffle()->first();
if ($randomItem) {
  echo $randomItem->intro()->kt();
}

Thanks so much. I think I am very close to making this work. I added the blueprint to my home.yml file and added the 3 intros via the panel. I also added the random entry code to my home template. Now I am seeing all 3 intros displayed at the same time (actually I am seeing 4 intros displayed so one of them appears to be repeating). Also, the last intro displayed (#4) is the only one that changes/shuffles when the page is reloaded.

Kurt

The code I posted above should work perfectly fine. Please post your home.php template code.

It’s working now. I had an error in the opening PHP tag. Thanks so much!

Kurt