Once you have selected an HTML based template in the template editor, access the "Hooks script" group in the "Edit template..." panel to manage the custom script used to hook some template generation methods. Using hooks, it is possible to alter HelpNDoc's generation process to fine-tune it for specific requirements.

Hook "Help Id" generation

The Hook_HelpIds function can be used to customize how the Help ID topic property is produced. It is particularly useful for the HTML documentation format as the Help ID is used to produce each topic's file name and therefore, the URL used to access specific topics. Customizing the Help ID can therefore be used for search engine optimization (SEO) purposes.

Simple hook function

The following Hook_HelpIds function simply makes the Help ID upper-case:

function Hook_HelpIds(aTopicID: string; aHelpId: string): string;
begin
  Result := aHelpId.toUpper();
end;

URL-encoded caption hook function

The following Hook_HelpIds function will not use HelpNDoc's Help ID at all, but instead it will:

  • Get the topic's caption
  • Encode it to make it a valid URL

function Hook_HelpIds(aTopicID: string; aHelpId: string): string;
begin
  Result := HndUtils.UrlEncode(HndTopics.GetTopicCaption(aTopicId));
end;

More advance hook function

The following Hook_HelpIds function will not use HelpNDoc's Help ID at all, but instead it will:

  • Get the topic's caption
  • Make it lower-case
  • Replace any spaces with a dash
  • Filter any non alpha-numeric content

function Hook_HelpIds(aTopicID: string; aHelpId: string): string;
begin
  Result := HndUtils.FilterAlphaNumericString(HndTopics.GetTopicCaption(aTopicID).toLower().replace(' ', '-'), False, True, True);
end;