Template files
A template file, also called a view template, describes how to display a notice. This page describes:
-
the structure of a template file as a whole;
-
the directive that includes other files in it;
-
the comments and blank lines that explain and separate its parts.
Each part of a template file has its own page: the declarations, the sections, the template lines and their content.
Template file
A template file is a text file, with the extension .efx. It describes what to display for a notice, and how to
structure the information displayed.
<global-declaration> … --- TEMPLATE <template-name> --- … --- MAIN --- <template-line> … --- HEADER --- <header-line> … --- SUMMARY --- <template-line> … --- NAVIGATION --- <template-line> …
- <global-declaration>
-
optional, any number: a global variable, a dictionary declaration or a user-defined function declaration.
--- TEMPLATE <template-name> ----
optional, any number: a template section, which declares a callable template.
--- MAIN ----
the header of the main section, followed by its template lines (see Template line). You must write the header after template sections. Otherwise, it is optional.
--- HEADER ----
an optional header, followed by the lines of the header section: the parts of the header of the notice, then normal lines.
--- SUMMARY ---,--- NAVIGATION ----
optional headers, each followed by the template lines of the summary section or of the navigation section. The header, summary and navigation sections can appear in any order.
A template file has up to four parts, always in this order:
-
The global declarations define variables, dictionaries and user-defined functions for the whole file. You can write them in any order.
-
The template sections declare callable templates: named content that template lines display with
INVOKE. -
The main section describes the full display of the notice. With indentation, you nest template lines under other template lines. The template lines then form a hierarchy of template blocks.
-
The header, summary and navigation sections describe three more views: the header of the notice, a summary of the notice, and aids to move around it.
Every part is optional. A file that contains only comments, or nothing at all, is a valid template file that displays nothing.
You can use the names declared by the global declarations everywhere after their declaration, also in the header, summary and navigation sections. You can invoke the callable templates of the template sections in later template sections, and in the main, summary and navigation sections. Variables, dictionaries, user-defined functions and callable templates share one set of names, so you can declare a name only once in a file. You must declare a name before you use it.
An include directive inserts the content of another file. You can write comments and blank lines anywhere (see Comments and blank lines in templates).
Restrictions
-
A declaration that follows a template section or a template line is an error.
-
After one or more template sections, the main section must start with its header,
--- MAIN ---. -
The sections contain template lines only, apart from the
LETline that declares the parameters of a template section. A global declaration in a section is an error. -
A file can have at most one main section, one header section, one summary section and one navigation section.
Examples
DISPLAY Notice;
The smallest template file: one template line, which displays a fixed text.
WITH BT-00-Text DISPLAY $value;
A template file that displays data of the notice: the value of BT-00-Text, once for each occurrence of the field.
// Global declarations
LET text:$separator = ' / ';
LET text:?label-and-value(text:$label, text:$value) = concat($label, ': ', $value);
--- TEMPLATE show-number ---
LET number:$value;
DISPLAY #{name|BT-00-Number}: ${$value};
--- MAIN ---
1 WITH ND-Root DISPLAY #{auxiliary|text|notice-information};
WITH BT-00-Text DISPLAY ${?label-and-value('Text', BT-00-Text)};
WITH BT-00-Number INVOKE show-number(BT-00-Number);
WITH ND-Root DISPLAY ${string-join(BT-00-Repeatable-Text, $separator)};
--- SUMMARY ---
WITH BT-00-Text DISPLAY $value;
A template file with all four parts: global declarations, a template section, the main section and a summary section.
// This template file displays nothing.
A template file can be empty or contain only comments.
| An EFX-1 template file contained template lines only. Declarations, template sections, the header, summary and navigation sections, and include directives are new in EFX-2. |
See also: Indentation, Rules file
Include directive
The include directive inserts the content of another file into a template file. With it, you can split a large template file into several files, and share common parts between template files.
#include "<path>" #include "<path>";
- <path>
-
the path of the file to include, between double quotes. A relative path is relative to the folder of the template file being translated.
You can end the directive with a semicolon, but you do not have to.
Before the translator reads the template file, it replaces each line that contains an include directive with the full content of the named file. So you can put the directive wherever the content of the included file is valid: among the global declarations, among the template lines, or in a section.
The translator inserts the included content as it is. It ignores white space before #include, and the lines of
the included file keep their own indentation. So the level of an included template line depends on its own
indentation in the included file, not on the position of the directive.
An included file can contain include directives too. The paths in these directives are also relative to the folder of the template file being translated, not to the folder of the file that includes them. You can include the same file more than once.
You can write a comment after the directive, on the same line.
Restrictions
-
The directive must be the only content of its line, apart from white space before it and a comment after it.
-
You write
#includein lower case. -
The included file must exist. Its path must lead to the folder of the template file being translated, or to one of its subfolders.
-
A file that includes itself, directly or through other included files, is an error.
Examples
#include "common/declarations.efx"
WITH BT-00-Text DISPLAY ${$greeting}: $value;
#include "common/number-lines.efx" // lines for the numbers
Here the file common/declarations.efx contains the declaration LET text:$greeting = 'Hello';, and the file
common/number-lines.efx contains the template line WITH BT-00-Number DISPLAY #{name}: $value;.
WITH BT-00-Text DISPLAY #{name}: $value;
--- SUMMARY ---
#include "common/number-lines.efx"
An include directive in a section.
WITH ND-Root DISPLAY Root;
#include "common/text-child.efx"
If the file common/text-child.efx contains the line WITH BT-00-Text DISPLAY #{name}: $value; indented with one
tab, the included template line is nested under the line WITH ND-Root ….
| The include directive is new in EFX-2. |
See also: Include directive (in rules files)
Comments and blank lines in templates
Comments document a template file, and blank lines separate its parts. They have no effect on what is displayed.
// <comment>
- <comment>
-
any text up to the end of the line.
A comment starts with // and ends at the end of the line (see
Comments). In a template file, you can
write a comment:
-
on a line of its own;
-
after the semicolon that ends a template line or a declaration;
-
after a section header or an include directive;
-
in the parts of a template line that contain expressions: the context declaration, the conditions of a conditional display and the arguments of a template invocation;
-
in template text, where
//starts a comment when it follows a space or a tab, or when it directly follows a label block or an expression block. Inside a word, as inhttps\://,//is part of the text.
You can write blank lines and comment lines anywhere: between declarations, between template lines, and between the lines of the file that make up one template line written on several lines. They do not count for indentation, so you can indent a comment line in any way.
Restrictions
-
A comment in the template text of a template line hides the rest of the line of the file, including a semicolon written after the comment. Put the comment after the semicolon.
Examples
// Notice information
WITH BT-00-Text DISPLAY #{name}: $value; // the text field
WITH BT-00-Number // positive numbers only
WHEN BT-00-Number > 0 DISPLAY #{name}: $value // displayed when positive
OTHERWISE DISPLAY #{name}: -;
Comments on their own line, after a semicolon, in a context declaration and in template text that continues with
OTHERWISE on the next line.
WITH BT-00-Url DISPLAY See https\://example.com/help for help;
The // inside the web address is part of the text. Its colon is written \:, so that it does not start a
caption (see Caption).
| EFX-1 template files accepted comments on their own lines and at the end of template lines. |