<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 3.0//EN">
<html>
<!-- $Id: examples.ttml,v 1.4 2001/03/01 18:31:59 davidw Exp $ -->
<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>

&lt;?
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"
?&gt;

</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>

&lt;? if { 1 } { ?&gt;

&lt;h2&gt; True &lt;/h2&gt;

&lt;? }  ?&gt;

</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>

&lt;? 
set x 0 
while { $x &lt; 5 } { 
 hputs "\$x = $x&lt;br>"
 incr x
?&gt;

LOOP&lt;br>

&lt;? }  ?&gt;

</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>

&lt;? 
 hgetvars
if { [ array exists VARS ] } {
    hputs "&lt; ul>"
    foreach { vr } [ array names VARS ]  {
        hputs "&lt;li>(VARS) $vr = $VARS($vr)"
    }
    hputs "&lt;/ul>"
}

if { [ array exists ENVS ] } {
    
    hputs "&lt;ul>"
    foreach { vr } [ array names ENVS ]  {
        hputs "&lt;li>(ENVS) $vr = $ENVS($vr)"
    }
    hputs "&lt;/ul>"
}

if { [ array exists COOKIES ] } {
    
    hputs "&lt;ul>"
    foreach { vr } [ array names COOKIES ]  {
        hputs "&lt;li>(COOKIES) $vr = $COOKIES($vr)"
    }
    hputs "&lt;/ul>"
}

?&gt;

</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>

&lt;?
set i 1
hputs "&lt;table&gt;\n"

while { $i &lt;= 8 } {
    hputs "&lt;tr&gt;\n"
    for {set j 1} {$j &lt;= 8} {incr j} {
	set num [ expr $i * $j * 4 - 1]
	hputs [ format "&lt;td bgcolor=%2x%2x%2x &gt; $num $num $num &lt;/td&gt;\n" $num $num $num ]
    }
    incr i
    hputs "&lt;/tr&gt;\n"
}

hputs "&lt;/table&gt;\n"
?&gt;
</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="http://tcl.apache.org/mod_dtcl/">Return to the mod_dtcl homepage</a>
</p>

</body>
</html>
