Fetching data from children's subpage

Hello I am trying to fetch some data from a children’s subpage.
I tried a lot of ways. My last try was this :

<?php foreach(page('project')->children()->find("projectsub") as $projectsub): ?>
    <?= $projectsub->projecttext()->kt() ?>
<?php endforeach ?>

But all I get is this error message:

"Invalid argument supplied for foreach()"

And I am not sure what I am doing wrong here.

A foreach loop doesn’t work for a single page, only for page collections:

if ($projectsub = page('project')->children()->find("projectsub")) {
  echo $projectsub->projecttext()->kt();
}

But maybe you want something else?

1 Like

I understand! Thanks for this, that was exactly I was looking for.