Once Kiby is initialized, you ought to be able to use the page(), and site() functions to retrieve the equivalent of the equivalent of the $page and $site variables in your template. These functions are defined in the global scope, and are therefore available in all other contexts.
I tried to find a solution to it. The best way might be to try to use the build in function that create the current $page and use that function in the plugin.
Yeah, but not fully. They both use the same string as the base value, but kirby()->request()->path() returns a collection (you can iterate over the parts of the path string), while kirby()->path() returns the string.
You can use both as strings though, so it therefore doesnāt matter.
Please donāt even try to hack together the whole Kirby routing implementation to duplicate it in your plugin. It wonāt be robust enough to be reliable.
They probably wonāt work either.
Multi-language support is one example.
Conclusion: What I posted is a hackish solution. The true and only real solution would be to change the order of code invocation in the core so that plugins are loaded after the router has determined what page to use. That would probably break custom routes in plugins though, so it isnāt easy to implement at all. If you really care about this issue, please open it on GitHub. Discussing hackish solutions and their pitfalls isnāt worth it.