Instead of an event inside twig, it would also be possible to use an existing PHP event to replace the twig class loaded by the container by a child class defined in the extension, or redefine
template
inside the service.yml, so the container always provides your class instead of the regular template class. In that child class, you could then replace the method that you wanted your event in, detect your events, and then call the parent method.