I would like to create two fields: one in which you can pick another page, this will be on the project.yml template. and another one in which will display the other pages if this page is selected by them, this will be on the page.yml.
you should only be able to select pages with the page.yml template from the project page
currently i have a field in my project.yml
relatedPages:
label: Related Pages
type: pages
query: site.index.filterBy('template', 'page')
multiple: true
and on the page template I want to render all pages that have selected this page, something like:
referencedBy:
label: Referenced By Projects
type: pages
query: page.referencedByProjects
Thanks you
Is this just dummy code, or have you created a method called referencedByProjects? If not, you should create one in a page model for the page
Page type, that returns all pages with project blueprint, filtered by wether the current page is contained in the relatedPages field of those pages, something like
function getPagesReferencesThisPage(): Kirby\Cms\Pages
{
return site()->index()->template('project')->filter(fn($child) => $child->related()->toPages()->has($this);
}
Try to prevent the call to site->index() by narrowing down where these project pages are found
thanks texnixe. I don’t yet want to render these projects on the web page, I would like the pages selected on the project page in the panel to appear on the page page in the panel (see screenshot). you don’t need to be able to add or remove these pages in the in this field on the page page, purely visual
You should use a pages section with that query not a field, otherwise, you would have to select the pages before they would appear there, which doesn’t make sense.
I didn’t mean to show them in the template, that method was to be used in your blueprint to fetch the pages. Read the docs about page models. This is necessary because you cannot use a complex query like the one in the method directly in your blueprint