I’m trying to get values from fields, but randomly only one instead of for each.
for each is working like this:
<?php foreach(page("testimonials")->testimonials()->toStructure() as $testimonial): ?>
<?php echo $testimonial->text() ?>
<?php endforeach ?>
But I don’t get it randomly working. I tried a lot of variations of the below, with and without yaml()
, with and without toStructure()
, but unfortunately …
<?php $testimonials = page("testimonials")->testimonials()->yaml(); ?>
<?php $index = rand(0, sizeof($testimonials - 1); ?>
<?php //$testimonial = $testimonials[$index]; ?>
<?php //echo $testimonial->text() ?>
<?php echo $testimonials[$index]->text() ?>
Here’s my blueprint:
fields:
title:
label: Title
type: text
testimonials:
label: Testimonials
type: structure
fields:
name:
label: Name
type: text
text:
label: Text
type: textarea
buttons: false
[… other fields …]
Thank you very much for your great help on my project! : )