mod_dtcl examples |
These are some examples, rather limited ones, of what can be done with mod_dtcl.
Hello world | |
<? headers setcookie "foo" "bar" # we have to put this before any 'hputs' statements # once buffering is switched off, it is no longer possible to # maninuplate headers buffered off hputs "Hello world" ?> | |
Produces:
headers setcookie "foo" "bar" # once buffering is switched off, it is no longer possible to # maninuplate headers buffered off hputs "hello world" ?>
| |
Conditionals: | |
<? if { 1 } { ?> <h2> True </h2> <? } ?> | |
Produces:
if { 1 } { ?> True} ?> | |
Loops: | |
<? set x 0 while { $x < 5 } { hputs "\$x = $x<br>" incr x ?> LOOP<br> <? } ?> | |
Produces:
set x 0
while { $x < 5 } {
hputs "\$x = $x | |
Variables (environmental as well as those passed to the script)
| |
<? hgetvars if { [ array exists VARS ] } { hputs "< ul>" foreach { vr } [ array names VARS ] { hputs "<li>(VARS) $vr = $VARS($vr)" } hputs "</ul>" } if { [ array exists ENVS ] } { hputs "<ul>" foreach { vr } [ array names ENVS ] { hputs "<li>(ENVS) $vr = $ENVS($vr)" } hputs "</ul>" } if { [ array exists CLIENT_ENVS ] } { hputs "<ul>" foreach { vr } [ array names CLIENT_ENVS ] { hputs "<li>(CLIENT_ENVS) $vr = $CLIENT_ENVS($vr)" } hputs "</ul>" } if { [ array exists COOKIES ] } { hputs "<ul>" foreach { vr } [ array names COOKIES ] { hputs "<li>(COOKIES) $vr = $COOKIES($vr)" } hputs "</ul>" } ?> | |
Produces: hgetvars if { [ array exists VARS ] } { hputs "
| |
Create a table on the fly
| |
<? set i 1 hputs "<table>\n" while { $i <= 8 } { hputs "<tr>\n" for {set j 1} {$j <= 8} {incr j} { set num [ expr $i * $j * 4 - 1] hputs [ format "<td bgcolor=%2x%2x%2x > $num $num $num </td>\n" $num $num $num ] } incr i hputs "</tr>\n" } hputs "</table>\n" ?> | |
Produces: set i 1 hputs "
| |
In addition There are many, many other things you can do with mod_dtcl. You can, if everything is compiled right, load tcl modules, like libpgtcl.so (the Postgresql interface), so that you can interact with a database!
|