| <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 3.0//EN"> |
| <html> |
| <!-- $Id$ --> |
| <title>mod_dtcl examples</title> |
| <body bgcolor=white> |
| |
| <table bgcolor=black width=100%> |
| <tr> |
| <td align=center> |
| <font size=40 color=#ffffff> |
| <b>mod_dtcl examples</b> |
| </font> |
| </td> |
| </tr> |
| </table> |
| |
| <p> |
| These are some examples, rather limited ones, of what can be done with mod_dtcl. |
| |
| <p> |
| <table> |
| <tr><td><hr><b>Hello world</b></td></tr> |
| <tr><td bgcolor=gray><pre> |
| |
| <? |
| 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" |
| ?> |
| |
| </pre> |
| </td></tr> |
| |
| <tr><td> |
| Produces: |
| <p> |
| |
| <? |
| headers setcookie "foo" "bar" |
| |
| # once buffering is switched off, it is no longer possible to |
| # maninuplate headers |
| buffered off |
| |
| hputs "hello world" |
| ?> |
| |
| <p> |
| |
| |
| </td></tr> |
| |
| <tr><td><hr> |
| <b>Conditionals:</b> |
| </td></tr> |
| |
| <tr><td bgcolor=gray><pre> |
| |
| <? if { 1 } { ?> |
| |
| <h2> True </h2> |
| |
| <? } ?> |
| |
| </td></tr></pre> |
| |
| <tr><td> |
| Produces: |
| <p> |
| |
| <? if { 1 } { ?> |
| |
| <h2> True </h2> |
| |
| <? } ?> |
| </td></tr> |
| |
| <tr><td><hr><b>Loops:</b> |
| </td></tr> |
| |
| <tr><td bgcolor=gray><pre> |
| |
| <? |
| set x 0 |
| while { $x < 5 } { |
| hputs "\$x = $x<br>" |
| incr x |
| ?> |
| |
| LOOP<br> |
| |
| <? } ?> |
| |
| </pre> |
| </td></tr> |
| |
| <tr><td>Produces:<p> |
| <? |
| set x 0 |
| while { $x < 5 } { |
| hputs "\$x = $x<br>" |
| incr x |
| ?> |
| LOOP<BR> |
| <? } ?> |
| </td></tr> |
| |
| <tr><td><hr><b>Variables (environmental as well as those passed to the script)</b><p> |
| </td></tr> |
| <tr><td bgcolor=gray><pre> |
| |
| <? |
| 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 COOKIES ] } { |
| |
| hputs "<ul>" |
| foreach { vr } [ array names COOKIES ] { |
| hputs "<li>(COOKIES) $vr = $COOKIES($vr)" |
| } |
| hputs "</ul>" |
| } |
| |
| ?> |
| |
| </pre> |
| </td></tr> |
| |
| <tr><td>Produces:<p> |
| <? |
| 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 COOKIES ] } { |
| |
| hputs "<ul>" |
| foreach { vr } [ array names COOKIES ] { |
| hputs "<li>(COOKIES) $vr = $COOKIES($vr)" |
| } |
| hputs "</ul>" |
| } |
| |
| ?> |
| </td></tr> |
| |
| <tr><td><hr><b>Create a table on the fly</b><p> |
| </td></tr> |
| <tr><td bgcolor=gray><pre> |
| |
| <? |
| 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" |
| ?> |
| </pre> |
| </td></tr> |
| |
| <tr><td>Produces:<p> |
| <? |
| 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" |
| ?> |
| </td></tr> |
| |
| <tr><td><hr> <b>In addition</b><br> |
| |
| 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! |
| |
| <p> |
| |
| </td></tr> |
| |
| </table> |
| |
| <? dtcl_info ?> |
| |
| |
| <p> |
| <a href="index.rvt">Return to the mod_dtcl homepage</a> |
| </p> |
| |
| </body> |
| </html> |