Newbie question re fetching pages of subpage

Hi. I am completely new to Kirby/php and stuck on how to fetch and list the pages of a subpage. Would someone mind helping?

My site has a Services section:

services
    service-group-a         
        service-1 
        service-2
        service-3
    service-group-b
        service-1
        service-2
        service-3

I would like to list service-group-b subpages on my services page and I expected the code below to work but it doesn’t for some reason

 <?php foreach(page(‘service-group-b’)->children() as $service): ?>
 <a href="<?php echo $service->url() ?>">
<?php echo html($service->title()) ?>
</a>
<?php endforeach ?>

Hello @wbjp,
It’s hard to see from your post what’s happening mainly because you’re not using code blocks so the formatting is off.

Would you mind wrapping your code with three backticks ` before and after?

You should put three on the line that comes before your code and three on the line after.

For the folder structure, it would help if you could provide some sense of hierarchy by indenting the folders just so we’re sure to understand how it is structured. This is my assumption from your post:

services
  service-group-a 
    service-1 
    service-2
    service-3
  service-group-b
    service-1
    service-2
    service-3

I have fixed the code blocks above. @wbjp: As written above, proper code blocks help a lot, please use them in the future.

The page() helper needs the full path to a page:

<?php foreach(page('services/service-group-b')->children() as $service): ?>
 <a href="<?php echo $service->url() ?>">
   <?php echo $service->title()->html() ?>
 </a>
<?php endforeach ?>
```
Alternatively, you can do this:

```
<?php foreach(page('services')->find('service-group-b')->children() as $service): ?>
 <a href="<?php echo $service->url() ?>">
   <?php echo $service->title()->html() ?>
 </a>
<?php endforeach ?>
```

Sorry for not using code blocks and thanks so much for your help, now I understand ; )