Woof! Template Format
A Woof! Template Format (WTF) file is a file containing a combination of plain text and Tcl code that is processed to product the final text output. In the context of web servers, the text is generally HTML format text but does not have to be. Both layouts and page sections are normally generated from WTF files.
In its simplest form, a WTF fragment contains text with no characters that are special to Tcl. The output of the template processor is exactly the same as the fragment. For example,
<p>This is a paragraph.</p>
will be passed through by the WTF processor without any changes.
Dynamic content can be generated by including Tcl commands and variable references.
<p>Today's date is [clock format [clock seconds] -format %D]</p>
In this WTF fragment, the text between the characters is evaluated as Tcl code and replaced by the result of the evaluation in effect printing the current date. The exact syntax and semantics of processing is defined by Tcl's subst command which is in fact used as the basic engine in template processing.
In addition, lines beginning with the % character are treated entirely as Tcl code but the resulting values are not inserted into the template output. This is most useful for control structures or short intermediate calculations. For example, the following fragment
<table> % for {set i 1} {$i < 6} {incr i} { <tr><td>$i</td></tr> % } </table>
will generate a HTML table of integers from 1 to 5.
You can also use the %(
and %)
block
delimiters to enclose a block of Tcl code. For example, the lines
% # Initialize variables % set i 1 % set j 2 % set k 3
can also be written as
%( # Initialize variables set i 1 set j 2 set k 3 %)
Template context
The processing of WTF fragments is implemented by the
command html_frag1 in the
context of the caller. In the case of Woof!, this context is the
controller object handling the request. Therefore all commands and
variables defined in the context of that controller's methods are
available in the template with appropriate declarations. In particular,
note that my variable
statements are required in the
template file to bring the controller object member variables into the
template scope.
Comments
You can insert comments into an HTML file by starting a line with the sequence %#. The % indicates this is Tcl line, and the # is the Tcl comment character.
1 This command is based on an enhanced form of the substify command from the Tcl wiki.