Templates

For wizards, several variables are predefined, such as templateName, targetFolder, date, and author; others, like targetFileName, targetTypeName, simulationFolderName, nedPackageName, etc., are defined only for certain wizard dialogs. A full list of variables is provided in the Appendix.

Generating multiple files

By default, templates are processed and copied with the same name (chopping the .ftl extension), but it is possible to redirect the output of the template to a different file using the <@setoutput path=.../> macro. The filename can contain slashes, too, which means that one can write files in a different folder. If the folder does not exist, it will be created. For example:

<@setoutput path=targetFileName/>

If filename is empty, the directive restores output to the original file name (the template’s name). This also works if a folder name is given and only the file name is missing (<@setoutput path="src/">). Then, it will write the file with the original name but into the specified folder.

Note

If there are multiple setoutput macros with the same file name within a template, the content will be concatenated. Concatenation only works within one template; if you have multiple templates writing into the same file, they will overwrite each other’s content. It is undefined which one will win.

Conditional file creation

Empty and blank files (i.e. those containing only white space) will not be created (i.e. processing will skip writing it without any question, warning or error). This allows you to easily create files conditionally; you just have to surround the file body with <#if>..</#if>.

Note

The above rule also means that one cannot even deliberately create empty files with templates. However, this "limitation" is easy to overcome. Most file formats (NED, C⁠+⁠+, INI, XML, etc.) have a comment syntax, so you can write a file that contains only a comment ( // file intentionally left blank ). Alternatively, you can create an empty file using the FileUtils Java utility class (<@do FileUtils.createFile("empty.txt", "")!/>).

Note

Although blank files are not created, the template engine will not delete an existing file that happens to be already there with the same name.