I think I got an answer. I haven't tested this yet but I think I can do it this way.
First, HTML5 has the capability to add custom data attributes to each tag. With that in mind, I can do the following, given we have a targetController
class with a method named foo()
and a front controller that appends the word "Controller" to every request:
<select data-target="target" data-action="foo">
</select>
This way I can call a certain controller and invoke a certain action before the document gets rendered! Now, instead of just including a template the regular way, I can load them through a DOM library that will delegate the controller loading to either the front controller as a regular request or through a class that might do the controller loading. This way I don't have to rely on javascript to do anything. I will definitely test this solution once I get to start working!