get().. either use
The situation is like this:
I pass all front-end requests through WPEmerge -
MyApp::route()->all() so when I invoke some regular page, a view
wp-content\themes\my-theme\views\page.php is automatically displayed.
I'm wondering how to achieve this:
I like this route -> controller -> view schema, but I don't want to create routes for all standard WP URLs .
I'd like to have some controller(s) in the middle to inject some data (variables) when needed to some of the standard-route-views.
How can I create a controller that would be automatically invoked for those standard WP routes before (in this case the page.php) view is served?
Should I use middleware for that? One method that would check what route is this and delegate handling of this request to some dedicated classes?
If you want to inject some data into a view regardless of how it is rendered you can use View Composers which do just that: https://docs.wpemerge.com/#/framework/views/view-composers
There's an article on the subject that you may find useful as well - it uses outdated syntax but the concepts are the same: https://wpemerge.com/2019/01/24/view-composers-passing-data-and-staying-dry/
<?xml version="1.0" encoding="utf-8"?> <!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">