Subpage content is not rendering on front end

My homepage has a gallery of project subpages that link to the project.php template

None of the code in inside my main tags is rendering to the front end

<main>

<?php foreach($page->builder()->toBuilderBlocks() as $block): ?>
<?php snippet('blocks/' . $block->_key(), array('data' => $block)); ?>
<?php endforeach ?>

<?php foreach ($page->children()->listed() as $architect): ?>
<a href="<?= $architect->url() ?>">
Link Title
</a>
<?php endforeach ?>

</main>

My Blueprint:

title: Project

    tabs:
      content:
        label: Content
        icon: text
        sections: 
          fields: 
            type: fields
            fields:
              hero_image:
                type: files
                max: 1
                width: 1/2
                uploads: false
                multiples: false
                label: Project thumbnail Image
              key:
                type: text
                width: 1/2
                label: Key(s)

              builder:
                type: builder
                label: Page Builder
                fieldsets:

                  mediablock: 
                    label: Media Block
                    fields:
                      media:
                        type: files
                        label: Image or Video Embed
                        width: 1/1

                  textblock: 
                    label: Text Block
                    fields:
                      text:
                        type: text
                        label: Text Body
                        width: 1/1

          architect: 
            type: pages
            layout: cards
            max: 1
            templates: architect
            image: 
              cover: true
              ratio: 1/1

$page always refers to the current page, so if you are in the home page template (presumably home.php), $page refers to the home page, not your projects page.

You can use the page() helper to retrieve the page you need

<?ph pif ( $p = page('path-to-page') )  : ?>
<?php foreach($p->builder()->toBuilderBlocks() as $block): ?>
<?php snippet('blocks/' . $block->_key(), array('data' => $block)); ?>
<?php endforeach ?>
<?php endif; ?>

Hmm ok so my code is in project.php so $page is correct yet nothing is coming out on the front end

In your first sentence you are talking about the home page. Is the home page relevant for your question? If so, in what way?

I was just hoping to provide some context on the site sorry but might have caused more confusion!

The issue is on the project.php page - none of my for loops are working as there is no code rendered inside the main tags

Is that all that is in your template? Is debugging enabled? What exactly is rendered? A blank page? The header with navigation?

If you echo the title and the template right after the opening main tag, are they rendered as expected? What is the result?

<main>
<?php echo $page->title(); ?>
<?php echo $page->template(); ?>

Please also post your content folder structure (with visible text files)

That is all that is in the template other than header and footer

echoing the title and template works as expected but my page-builder doesn’t

Also this is the code inside snippets/blocks/text.php for page-builder

<section class="textblock">
<?= $data->text()->kt() ?>
</section>

I think the names of your snippets are wrong: _key refers to the name of the fieldset, so it should be textblock.php instead of text.php and mediablock.php instead of whatever you called that snippet.

1 Like

omg that was it - thank you so so much