I have a question concerning the foreach loop in kirby (but it’s probably more a lack of php knowledge…).
I’m trying to shuffle and list the titles of all the files AND all the subpage in the same foreach loop.
Of course I could write two different foreach loop but since I want to shuffle all the content, it has to be in the same loop.
here’s an exemple of what i’m trying to achieve. My content file would be like :
I would like to return :
Is it possible to add two variables in the same foreach loop ?
I would guess :
$subpages = $page->children()->title(); $images = $page->myimages()->tofiles(); <?php foreach(($subpages + $images)->shuffle() as $item): ?> <h1><?= $item->title() ?></h1> <?php endforeach ?>
I know the ($subpages + $images) doesn’t work, i think i have to do an array but I don’t know how.
Any idea ?