Templates

Templates

Templates are based on the IWML Template tag. IntraWeb adds some extra functionality for Delphi.

This functionality adds support for loading templates from files on disk. This preserves backward functionality with v15 pages, but also keeps the advantages. The most prominent advantage is that end users may change your application layout as a customization option.

With IntraWeb 17 you can use external HTML files as in IntraWeb 15, embed the template into the Template’s HTML property, or embed it in the loader HTML.

External Template Files

The external template functionality of IntraWeb 17 is similar to IntraWeb 15 however it is a discrete implementation and differs in some details.

Template Directory

The template directory is named Templates. You can manually set this location in the ServerController.TemplateDir:

If this property is empty, IntraWeb will initialize it for you.

First it will look in the same location as the .exe for a directory named Templates. If this directory exists it will use it.

If the above directory does not exist, and the .exe path ends in \Release\ or \Debug\, then IntraWeb will look for a Templates directory at <.exe location>\..\..\Templates. This is useful when you are running your application from the IDE and allows the template directory to exist in the project folder and also be used by all build configurations.

Naming

Like IntraWeb 15, IntraWeb 17 uses the same template directory and same name matching. A page named Contact will look for a file named Contact.html in the templates directory.

Requirements

IntraWeb will load the template from the file system only if both:

  • The Template control is the root of the page.
  • The HTML property is empty. If it is not empty, the property will be used instead.

With IntraWeb 17 you do not need to style every template and can instead specify a global style which will be merged with all pages whether they use templates or not.

The syntax of these files is the same as the HTML property of the Template tag.

Body Only

Only the body of the HTML file will be used. The header will be disposed of.

The body tag must not contain any attributes and must be of the simplest form of just <body>. This is because the parser is simplistic and fast. Body attributes are not supported in templates, so adding parsing support for them only serves to complicate the parser unnecessarily. If attributes are added to the body tag, the parser will raise an exception stating that it cannot find the body tag.

Loading of scripts or attributes in the body tag should be added using other methods such as a custom HTML loader file.

See Also