Hi Georg,
did you read the chapter after the chapter my link was pointing to?
https://docs.moodle.org/dev/Templates#Template_requires_JavaScript
There is a description how to execute the js after rendering the template.
templates.runTemplateJS(javascript);
This requires the js in the {{#js}}...{{/js}} section of the template.
Best regards
Andreas