Issue with nested pages: The parent for the query "kirby.page("note")" cannot be found in the section "drafts"

Hey everyone,
I tried to extend the starterkit for one more level regarding the page structure. I would like to have a nested structure as follows:

notes
--note
---subnotes

Right now, I have three blueprints:
notes.yml

title: Notes
columns:
  - width: 1/1
    sections:
      drafts:
        extends: sections/note
        headline: Drafts
        status: draft
      unlisted:
        extends: sections/note
        headline: In Review
        status: unlisted
      listed:
        extends: sections/note
        headline: Published
        status: published

note.yml

title: Note
columns:
  - width: 1/1
    sections:
      drafts:
        extends: sections/notes
        headline: Drafts
        status: draft
      unlisted:
        extends: sections/notes
        headline: In Review
        status: unlisted
      listed:
        extends: sections/notes
        headline: Published
        status: published

and subnote.yml

title: Subnote
status:
  draft:
    label: Draft
    text: The dossier is still in draft mode. It can only be seen by editors with panel access.
  unlisted:
    label: In Review
    text: The dossier is online and can be visited with the direct URL. The team must still give the final go to publish it.
  listed:
    label: Published
    text: The dossier is online and listed in the blog
columns:
  - width: 1/1
    fields:
      introduction:
        type: textarea

Furthermore, I have the sections:
notes.yml

type: pages
headline: Notes
parent: kirby.page("notes")
info: "{{ page.published }}"
template: note
empty: No notes yet
sortBy: date desc
image:
  query: page.cover
  cover: true
  ratio: 3/2

and note.yml

type: pages
headline: Note
parent: kirby.page("note")
info: "{{ page.published }}"
template: subnote
empty: No subnote yet
sortBy: date desc
image:
  query: page.cover
  cover: true
  ratio: 3/2

Although I applied the logic of ‘notes’ to ‘note’ it throws an error:
The section “drafts” could not be loaded: The parent for the query “kirby.page(“note”)” cannot be found in the section “drafts” when I try to access a ‘note’ page.
It looked fine when I removed parent: kirby.page("note") from the subnotes.ylm but got an error in return when I tried to loop over the children of the ‘notes’ pages.
I don’t know what to change anymore to try to resolve this error so I appreciate any help!

Please don’t use the quote button for code snippets but three backticks before and after your code snippets, otherwise it is completely unreadable. I will fix it for now, but please keep this in mind for the future.

three-backticks

Thanks, will keep it in mind!

The notes.yml section should be use in the notes.yml page blueprint:

title: Notes
columns:
  - width: 1/1
    sections:
      drafts:
        extends: sections/notes
        headline: Drafts
        status: draft
      unlisted:
        extends: sections/notes
        headline: In Review
        status: unlisted
      listed:
        extends: sections/notes
        headline: Published
        status: published

The in your note.yml page blueprint, you should use the note section:

title: Note
columns:
  - width: 1/1
    sections:
      drafts:
        extends: sections/note
        headline: Drafts
        status: draft
      unlisted:
        extends: sections/note
        headline: In Review
        status: unlisted
      listed:
        extends: sections/note
        headline: Published
        status: published

But the note.yml section should not have an explicit parent, because a page call note will not exist:

# blueprints/sections/note.yml
type: pages
headline: Note
info: "{{ page.published }}"
template: subnote
empty: No subnote yet
sortBy: date desc
image:
  query: page.cover
  cover: true
  ratio: 3/2

Thank’s for the reply. My page note should have a page where all subnotes are displayed with
->children()
So I would like the page note to exists. Can you give me a hint where to change things to be able to create that page?

Just to get this right:

The first level parent is notes, then underneath that page you only want one note page (not multiple children), and then this single note page can have multiple subnotes ? I was under the impression that you wanted multiple note type children under notes which would in turn have subnotes.

I have four notes pages, each of them has three note pages each of which has three subnotes. I would like to have a page for each note on which i loop over its children subnotes. This however throughs an error when opening one of the note pages:
Call to a member function children() on null

return function () {
    return page('note')
        ->children()
        ->listed()
        ->sortBy('date', 'desc');
};

That’s what I already said above, you don’t have a page that is called note (or in any case, there can only be one page with the slug note inside one parent folder.

Additionally, the page helper needs the full path to the page, and since any note page is a child of notes, the path would be page('notes/note') or whatever the real slug is.

But since you have multiple of these pages, it wouldn’t make sense to hardcode the path.

But is it possible at all to create a nested tree structure like this in kirby? Multiple child pages each having multiple child pages? Sorry if I misunderstand you!

<?php foreach ($articlegroups = $site->page('notes')->children() as $articlegroup): ?>
< ?php foreach ($articles = $articlegroup->children() as $article): ?

works perfetctly but

<?php foreach ($articles = $page('note')->children() as $article): ?>

at note.php does not and I don’t really understand why because from my understanding note and notes should function the same.

Yes, that is perfectly possible. But I don’t really understand in which template you are trying to use that code. It doesn’t usually make sense to try and fetch dynamic pages by there IDs. I think we somehow are talking cross purposes and need to clarify what exactly you want to do where.

Sorry for explaining so badly.

I have this setup:

-Page A (notes.txt)
--Page A-1 (note.txt)
---Page A-1-1 (subnotes.txt)
---Page A-1-2 (subnotes.txt)
--Page A-2(note.txt)
---Page A-2-1 (subnotes.txt)
---Page A-2-2 (subnotes.txt)

-Page B (notes.txt)
--Page B-1 (note.txt)
---Page B-1-1 (subnotes.txt)
---Page B-1-2 (subnotes.txt)
--Page B-2(note.txt)
---Page B-2-1 (subnotes.txt)
---Page B-2-2 (subnotes.txt)

I have a random page XYZ.php where am executing

<?php foreach ($articlegroups = $site->page('notes')->children() as $articlegroup): ?>
< ?php foreach ($articles = $articlegroup->children() as $article): ?

to show the content of all subnotes pages grouped into their note and notesgroups – wich works perfectly fine. The issue occured when I tried to also be able to look at the note groups individually, e.g. to open Page B-2(note.txt) from the CMS and to display it’s children there via the line <?php foreach ($articles = $page->children() as $article): ?> in note.php.

I hope this explains a little better what I am trying to achieve.

And in which template are you trying to use this code? Note that you can always get the current page with $page.

That was a copy and paste error, the correct line I used is above!

But if you are in the note.php template, this code will give you all subnotes of the current note type page. Is that not the intended behavior?

Yes, it is! But it throws the error:
Call to a member function children() on null

return function () {
    return page('note')
        ->children()
        ->listed()
        ->sortBy('date', 'desc');
};

Because it should be $page not page('note')(in a template or controller), but looks as if you are using this in a collection?

A collection doesn’t make sense here.

I removed the collection and now it works! Thanks a lot!