So assets()
would probably look something like this (just sketching the idea):
// kirby()->modules()->asset(__DIR__ . DS . 'assets' . DS . 'css', 'assets/myPlugin/css')
public function assets($dir, $route) {
if($page = page($route)) return false;
return kirby()->routes(array(
array(
'pattern' => $route . '/(:all)',
'action' => function($file) use($dir) {
$path = $dir . DS . $file;
if(f::exists($path)) {
return new Response(f::read($path), f::extension($path));
} else {
return Response::error();
}
}
)
);
}
That should work also for subdirectories with assets. What error would be appropriate?
Great starting point. My take on this:
// kirby()->modules()->assets(__DIR__ . DS . 'assets' . DS . 'css', 'assets/myPlugin/css')
public function assets($dir, $route) {
// TODO: Is this a good idea here?
// Might be confusing if you happen to create the page and suddenly the asset stops working
// Maybe the asset should override the page
if($page = page($route)) return false;
return kirby()->routes(array(
array(
'pattern' => trim($route, '/') . '/(:all)',
'action' => function($file) use($dir) {
$path = $dir . DS . $file;
if(is_file($path)) {
f::show($path);
return false;
} else {
return site()->errorPage();
}
}
)
);
}
Well, I think it would be even more confusing if you create a page and you canβt access it because some plugin developer did choose a way to generic route which overrides it. So by returning false
the plugin would know abut a conflict with a page and could maybe deal with it?
Yeah, maybe you are right. Maybe the plugin developer could print a warning or choose an alternate route (or use a more specific one in the first place ;)).
I moved the discussion about the implementation from the thread about the general development of plugins.
Also added asset routes and autocss/autojs handling to the PR. So now it is all about improving, refactoring, renaming, finding and fixing errorsβ¦
3 Likes
Any news about plugin bundles? I guess it will not be in 2.3, right?
No ETA for that, but we think we have figured out an even better way to handle them.
1 Like