Hello , quite a while no kirby forum
On this particular kirby site, I want that whenever a url such as this is visited:
.../projects/anyProjectName/anyInstanceName
…the following things happen:
- the url is not changed
- but the loaded page is
.../projects/anyProjectname/
instead - 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.
/edit
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.
edit/
/edit2
Ok I read the docs closely, and think I got it working with the following code:
// Routes
c::set('routes', array(
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);
}
)
));
edit2/
I am on ‘2.5.5’ but could probably upgrade if necessary.
Thank you!!