Routing, keeping urls, and passing parts of them as variables to the page

Hello :slight_smile: , quite a while no kirby forum

On this particular kirby site, I want that whenever a url such as this is visited:


…the following things happen:

  1. the url is not changed
  2. but the loaded page is .../projects/anyProjectname/ instead
  3. and “anyInstanceName” is passed to the page as a variable

Why I want to do this is perhaps a bit convoluted to explain, but let’s say that my page has a single default template. The template then includes a project snippet , which loads all instances of the project using an instance snippet.

So I want anyone visiting an instance, to just load the parent project (which already loads all instances) and use the instance name in the url to “open” the requested one.

Oh, and I want to keep the url unchanged because it just makes sense.:tipping_hand_man:


I forgot to add that I am looking at routes to accomplish this.

And I think I can accomplish 2 and 3, but not sure how to accomplish 1.



Ok I read the docs closely, and think I got it working with the following code:

// Routes
c::set('routes', array(
		'pattern' => 'projects/(:any)/(:any)',
		'action'  => function($project, $instance) {
			// search for the project's page
			$page = page('projects/' . $project);
			// add instance as additional data
			$data = array(
				'instance' => $instance
			// return it all
			return array($page, $data);			


I am on ‘2.5.5’ but could probably upgrade if necessary.

Thank you!!