On a project I am working on, I need to be able to define the HTML returned, instead of returning the full page. So I thought of using snippets to return exactly the content I need. Now, I need routes to these page fragments. Is it possible to pre-generate these routes?
I am using this function to generate them:
function generate_spots_routes() {
$spots = kirby()->page('spots')->children();
$routes = [];
foreach($spots->toArray() as $spot) {
$routes[] = [
'pattern' => $spot['id'],
'action' => function() {
return snippet($spot['uid'], ['data' => kirby()->page($spot['uid'])], true);
}
];
}
return $routes;
};
and then in config.php:
return [
'routes' => [...generate_spots_routes()]
];
and the page breaks. What am I doing wrong?