Page children urls in other pages

I feel like this should be simple enough but the solution is eluding me.

I’m setting up a site with projects and a store. The idea is to keep the information for a particular project and the store data that relates to it all together. A single touch point. Right now everything is in a ‘project’ blueprint which has a shop toggle field to filter it in the store.

How would I set it up so I can view and click through the store filtered projects in the store section while keeping the url in the /store/item configuration? (/store/project-1 as well as /projects/project-1). It’s easy enough to display a filtered collection of store items but the children urls point to projects.

I’m wanting to use a single source of content (with children) in two usage scenarios with different page templates and urls.

Suggestions would be most appreciated!

If I understand this correctly, you want to show the same content under two different URLs?

Yes exactly, and use a corresponding page template for each parent/child scenario.

From a SEO perspective, serving the same content under multiple URLs is not a good idea at all.

To change the URLs of the pages, you would need a page model that defines the children of the original projects parent as (virtual) children of the store parent.

Great thank you for the help Sonja, you guys rock!

A quick virtual page follow-up question:
Is there a quick way to associate all the content fields or do I have to do them all like this:

'content' => [
    'title' => $storePage->title(),
    'url' => $storePage->url(),
]

You can assign the content array:

'content' => $page->content()->toArray(),

Haha yes! As soon as I submitted the question I said, wait a sec…and did the same thing.

Thanks again, and enjoy the rest of the weekend!

1 Like

Hello again,

I noticed that the virtual pages created with this method no longer work for me in the latest version of kirby. I did a simple test with the starterkit and get the same error. Any help you can offer would be most appreciated.

A ‘test’ page model…

// /site/models/test.php
class TestPage extends Page
{
	public function children()
	{
		$pages = [];
		$photographyPages = site()->children()->findBy('intendedTemplate', 'photography')->children();

		foreach ($photographyPages as $p) {
			$pages[] = [
				'slug' => $p->slug(),
				'template' => 'test-item',
				'files' => $p->files()->toArray(),
				'content' => $p->content()->toArray()
			];
		}

		return Pages::factory($pages, $this);
	}
}

What exactly doesn’t work, what is the error you get? In a quick test with a 3.7.0.2 Starterkit, the thing that doesn’t work is thumbs.

Thanks for following up Sonja.

If I hit the new page [starterkit.url]/test - I get a garden variety ‘page cannot be found’ 404 error.

I’m using the 3.7.0.2 Starterkit as well with Valet. The only other change I made is adding ‘define(‘KIRBY_HELPER_DUMP’, false);’ to the index.php file.

Actually I figured it out.
When I have a blueprint for the page it looks like it’s adding the virtual children.

Thanks again.