Hello,
The CreateDocxFromTemplate class inheritances CreateDocx, so you can use the same methods.
There's a documentation page about the ways to generate DOCX files with phpdocx:
https://www.phpdocx.com/documentation/cookbook/add-contents-document-types
Anyway if you are using a template, the easiest approach is adding the TOC using MS Word and the fill it using phpdocx (adding contents that are supported in the display levels). The previous script was just an example to illustrate how headings are added to the TOC.
Regards.