When interpreting a template file, HelpNDoc will automatically save the printed content to the documentation's output directory and use the template file name, without the ".pas" part. For example, the "topics.pas.html" file will be interpreted and the result will be written in the "topics.html" file.

As it isn't possible nor sane to create a template file for every single file HelpNDoc has to generate, the template system has a special property to switch the file currently being written. The code required to do that is:

HndGeneratorInfo.CurrentFile := 'my-new-file.html';

When the template system interprets that line, it will automatically output any further content to the file specified, in the documentation's output directory. This trick is used by the CHM and HTML templates to output each individual topics into their own HTML file:

// Loop through each topics
for nCurTopic := 0 to length(aTopicList) - 1 do
  // Change the current output
  HndGeneratorInfo.CurrentFile := aTopicList[nCurTopic].HelpId + '.html';
  // Write the content of the topic to that file
  // ...