How would one write a block hook that renders a custom menu depending on the current URL, with the active trail applied? I cannot do it with a regular menus, since they are cached. With custom I mean different menu items for different users.
An example menu could look like this when looking at Users X's profile
|-- User X's profile (active)
|-- User X's groups
|-- Group A
|-- Group B
|-- Group C
But if I browse to my own user profile, go to settings, the menu might look like this
|-- My profile
|-- My settings
|-- Profile settings (active)
|-- Group settings
|-- My groups
|-- Group X
|-- Group Y
|-- Group Z
It would be very easy to just create a block that outputs this in plain HTML. But as said above, I need the active-trail applied on the links. And I also only want to edit the routes from the different menu hooks, not hard code or anything similar.
Any suggestions?