What is the purposes of attribute filetype in a TemplateFunction (and why it get's not automatically set until I extracting the subtemplate form the parent template)?
The file type in the template function has the same purpose as the file ending in the template editor. It chooses a syntax style model to highlight language keywords and comments.
If your template function generates java code, use java als filetype. If you plan to write C++ code, use hpp or cpp as file type.