Calling on page children within page text field? Using php?

Hi all,

So my website is set up as a portfolio/archive, which doesn’t require much nesting and is basically all contained within one “works” folder. However, there is one piece which i want to contain subpages and link to them, but i can’t add this into the php template as no other page on the site has child pages this way. It doesn’t seem like calling on the page’s children using php within the .txt file is a thing; what would be the most efficient way of accomplishing this?

(This is what i would want it to look like if it were possible to use php within a text field:)

Title: Principalities
Date: 2023-03-01
Description: Ongoing mail-based publication/personal blog established in 2023. See:
    <?php foreach ($page->children()->listed()->flip() as $item): ?>
        <a class="green" <?php e($item->isOpen(), 'aria-current="page"') ?> href="<?= $item->url() ?>">
            <?= $item->title()->esc() ?>
    <?php endforeach ?>
Cover: (image: 1_issue3.png imgclass: coverimage)
Tags: publication

Well, as you already realized, you cannot put your PHP code into a text file, it would never be executed.

There are several ways to approach this.

  1. In your template, check if you are on page x or check if the page has subpages, then render the snippet based on this condition.

  2. Use a custom kirbytag that is automatically rendered when when you call the kirbytext() method on your field (KirbyTags | Kirby CMS)

  3. Use a placeholder that is then replaced by the snippet (similar to No. 2, only different syntax/approach (The power of placeholders | Kirby CMS).

I’ve got it to work with your first method : ) Thanks, Sonja!!