I use ajax to load page content into an overlay and the routing function to get to this state with a direct URL access. It works exactly the way I want but only for one page:
c::set('routes', array(
array(
'pattern' => 'projects/(:any)',
'action' => function($modal) {
$kirby = new Kirby();
$page = page('projects')->find($modal);
if($page) {
$html = $kirby->render($page);
return new Response($html);
} else {
$page = site()->errorPage();
site()->visit($page);
}
},
'method' => 'POST'
),
array(
'pattern' => 'projects/(:any)',
'action' => function($modal) {
$page = page('projects')->find($modal);
if($page) {
$data = array('modal' => $page->url());
return array('home', $data);
} else {
$page = site()->errorPage();
return site()->visit($page);
}
}
),));
But as soon as I try to add this for another page like this:
c::set('routes', array(
array(
'pattern' => 'projects/(:any)',
'action' => function($modal) {
$kirby = new Kirby();
$page = page('projects')->find($modal);
if($page) {
$html = $kirby->render($page);
return new Response($html);
} else {
$page = site()->errorPage();
site()->visit($page);
}
},
'method' => 'POST'
),
array(
'pattern' => 'projects/(:any)',
'action' => function($modal) {
$page = page('projects')->find($modal);
if($page) {
$data = array('modal' => $page->url());
return array('home', $data);
} else {
$page = site()->errorPage();
return site()->visit($page);
}
}
),
array(
'pattern' => 'contact',
'action' => function($modal) {
$kirby = new Kirby();
$page = page('contact')->find($modal);
if($page) {
$html = $kirby->render($page);
return new Response($html);
} else {
$page = site()->errorPage();
site()->visit($page);
}
},
'method' => 'POST'
),
array(
'pattern' => 'contact',
'action' => function($modal) {
$page = page('contact')->find($modal);
if($page) {
$data = array('modal' => $page->url());
return array('home', $data);
} else {
$page = site()->errorPage();
return site()->visit($page);
}
}
),));
I get this error message “Missing argument 1 for Kirby::{closure}(), …”
This is how my modal div looks like:
<div id="modal-container" data-modal="<?php echo isset($modal) ? $modal : '' ?>" class="modal"></div>
Would be super nice if someone can tell me what I am doing wrong here.
Thanks in advance