What is it

STT (Smalltalk Templates) are HTML pages which contain embedded smalltalk code.
The code is embedded as HTML/XML PIs (Processing Instructions).

They are comparable to PHP- or other 'active server pages' in functionality.

Examples


program source
Hello World Source(helloWorld.stt)
Reflection (showing my own source) Source(reflection.stt)
Calendar Source(calendar.stt)
Currency Exchange Source(currencyExchange.stt)
99 Bottles Of Beer Source(99bottlesOfBeer.stt)
99 Bottles Of Beer, improved Source(99bottlesOfBeer_v3.stt)
Multiplication Table Source(multiplication.stt)
Factorial Table Source(factorials.stt)
Factorial Table (eXept body style) Source(factorials_e.stt)

Writing Smalltalk Server Pages

An STT page script is stored in an .stt file and consists of HTML (text) fragments and Smalltalk (code) fragments.
Thus a date-enhanced Hello World script might look like this:
    <html>
     <body>
       <h1>Hello world!</h1>

       Today is <?stt = Date today ?>
       and the current time is <?stt = Time now ?>.

       <hr><address>Served by your friendly <a href=http://www.exept.de>ST/X WebServer</a></address>

     </body>
    </html>
In the above page, the smalltalk expression in the <?stt = ... ?> processing instruction is evaluated and its result is sent the #asString message, whose result is sliced into the page.

To see the webpage produced by the above code, run the helloWorld.stt script.

The following example demonstrates how any smalltalk control structure can be used; for example to generate a loop:
    <html>
     <body>
       <h1>Factorials!</h1>

       <table>
       <tr>
<?stt 
	1 to:10 do:[:i | 
?>
	   <td> <?stt = i ?> </td>
	   <td> <?stt = i factorial ?> </td>
<?stt 
	]
?>

       <hr><address>Served by your friendly <a href=http://www.exept.de>ST/X WebServer</a></address>

     </body>
    </html>
As in the first example, expressions contained in <?stt = ... ?> are evaluated and sliced into the page.
In addition, any smalltalk code can be embedded in <?stt ... ?> .

To see the webpage produced by the above code, run the helloWorld.stt script.

In general, an STT code fragment must have one of the following forms:

<?stt code ?>
General Smalltalk code. All code fragments are collected into a single method. Thus, local variables may only be defined at the very beginning of the stt-file (before any HTML-code).
Using stream protocol to a variable named "response", the code can also print HTML code; this becomes part of the resulting HTML page.
In addition, the requests parameters are avaliable via the variable "request", which provides url, parameters, referrer etc. (see the HTTPRequest class).

<?stt = exp ?>
A Smalltalk expression exp in <?stt = exp ?> must evaluate to a string or respond resonable to the asString message. The expression is evaluated, and the result is sent the #asString message; finally, the resulting string is printed onto the page as part of the resulting HTML page.
The strange tag syntax <?stt ... ?> follows the standard for so-called XML processing instructions.

Credits

This code was originally written by Federico Gregorio Stilman and only slightly changed as follows:

Notice

As the STT processor generates a single methods' code from the template page, local variable declarations can ONLY be placed into the very first section, AND this section must come BEFORE any other html or stt-section.
For example, the following page leads to an error:
    <!-- Some comment -->
    <?stt
	|local|

	local := 'fooBar'.
    ?>

    <html>
     <body>
       <h1>Hello world!</h1>

       Today is <?stt = Date today ?>
       and the current time is <?stt = Time now ?>.

       <hr><address>Served by your friendly <a href=http://www.exept.de>ST/X WebServer</a></address>

     </body>
    </html>
The reason is that the STT processor generates an inside-out-wrapped method, where every HTML text is converted into a nextPutAll-message argument, and the stt-sections remain as-is in the methods code. In the above example, this leads to the declaration of the 'local' variable to be placed after the nextPutAll-code for the 'Some comment' text.
For more details, please have a look at the "Comanche::STTTemplate >> asSmalltalkCode"-method.
Served by your friendly ST/X WebServer