How to link to subpage created within a structure?

I am trying to link to a subpage for each section created within a structure so that from the backend you can add a new project that links to the project.php subpage

My link is currently not working

folder structure:


<?php foreach($page->project()->toStructure() as $project):?>
    <a href="<?= $project->project()->url() ?>">
        <p><?= $project->title() ?><p>
<?php endforeach ?>   

        type: structure
        label: Filtered Projects 
            type: text
            type: pages
            layout: cards
              cover: true
              ratio: 1/1
<?php foreach($page->project()->toStructure() as $project):?>
   <?php if ( $p = $project->project()->toPage() ) : ?>
    <a href="<?= $p->url() ?>">
        <p><?= $project->title() ?><p>
  <?php endif ?>
<?php endforeach ?> 

You have to convert the page field value to a page object first, see the docs for the pages field.

1 Like

Hey thank you so much for your help!

I was hoping you might be able to assist with this further issue I’m having

I have a structure for creating projects and within that is the page field

Inside the page field I am using page-builder but the issue I’m having is that it doesn’t allow different content within the page builder blocks, if I change text in project 1 it changes it in project 2 as well

I’m still reasonably new to kirby to definitely open to alternative solutions if there is a better way to do this

Could you please share the blueprint for the project page?

What I don’t understand is why on the one hand you have this structure field which store content for the project pages and then on the other the pages themselves that again seem to have this information (like the title). Somehow that looks as if you are duplicating content for no obvious reason, but maybe I’m missing something here?

What is the purpose of the structure field? If the purpose is to select some pages to feature them somewhere, it would be sufficient to only select the pages in the pages field and get the rest of the information from each project itself?

What I’m trying to do with the structure field is to create a list of projects on the home page and each project links to that projects corresponding subpage containing further information about the project - This is so the user can add a project and subpage + it’s contents inside the structure field

I hope that makes sense, really appreciate your help

See project page blueprint below

title: Project

    type: builder
    label: Page Builder

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

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

Hm, I don’t really understand why this additional information is not stored in the project page itself unless you really want to change title, keys and image especially for display on the homepage. Otherwise this information belongs in the project page itself.

As regards the builder, at first sight I can’t see anything wrong with the field definition, but I don’t really understand what the issue is. currently I see one project page in your screenshot with a text body and the entry Project 2. So if you create a second project page with a different title, then the content between these two projects is always the same in the Panel?

Also, I assume that this second issue is totally unrelated to the first?