I apologize in advance if this is a total noob question and the answer should be obvious. I promise I searched thoroughly, I’m seriously stuck and would appreciate any nudge or hint in the right direction.
But only as long, as the project page is a sibling of the standard page. As soon as the project becomes a child of „projects“, the title is empty and I can’t figure out how to access the data and how to print the field content like „teaser“ and the image url.
Could someone please point me in the right direction?
Well, I think you can achieve this with a ‘page’ field type in your standard page blueprint. With this field, the editor can find a page (or in this case, featured project), by typing in the title of the project (let’s say: project/your_project)*.
// This will find the page by the value of the page fieldtype in your standard page :)
$featuredProject = $pages->find( $page->your_page_field() );
// Since the $featuredProject variable holds a Page Object, we can access all the data now :)
echo $featuredProject->title()->html();
echo $featuredProject->teaser()->kirbytext();
echo $featuredProject->teaser_image()->url();
*If someone knows how to limit the scope of the ‘page’ fieldtype to only a certain page-type (in this case /projects/ for example), it will be even easier for the editors!
The first solution is an alternative to the part that is already working: I can already access the desired fields, but only as long as the project and the referencing page are siblings.
Dang, I figured that much and that explains it.
texnixe’s suggestions work, but I was very much hoping to find a more dynamic approach. So there is no way to get the full path to the linked project? I definitely need to provide the parent?
Thank you for helping me finding my way around Kirby! it is much appreciated!
Ahhh, sometimes I’m just blind. It was a tough birth, but it finally sunk in, thank you so much!!
This is what I came up with, I hope it’s the Kirby way to go…
// get the selected project
$selectedProject = $page->featuredproject()->value();
// get all pages of type „project“, returns $pages (not required but I like going step by step)
$allProjects = $site->index()->filterBy('template', 'project');
// search in all projects for the selected project and return $page
$featuredProject = $allProjects->findByURI($selectedProject);