Version 10 of TclHttpd: The .tml File

Updated 2004-06-23 13:35:27

The .tml file is a good place to put variables and small procedures (you'll want to put most of your procedures in custom libraries) that are commonly used in your TclHttpd application. For those of you who have worked with ColdFusion, the .tml file is similar to the application.cfm (the .tml is more powerful though, since it's a Tcl script). Here's an example .tml that also features a skeletal session handling routine:

 # Application navigation links
 set primary_nav {
     Home home /tcl/index.tml
     {My Configurations} configs /tcl/my-configs.tml
     {Configure A New Truck} new /tcl/new.tml
     {Truck Wizard} wizard /tcl/wizard.tml
     {Preferences} options /tcl/options.tml
     Contact contact /tcl/contact.tml
     {Quit} quit /tcl/quit.tml
 }

 # If this is set to 1, error messages will be shown in the error
 # template. This should be set to 0 in a production environment
 set errors_to_browser 1

 # Some basic application variables

 # Email of the guy or gal in charge
 Doc_Webmaster [email protected]

 # Template for 404 error
 Doc_NotFoundPage /project/tcl/notfound.tml

 # Template for 500 error
 Doc_ErrorPage /project/tcl/error.tml

 # Default preferences
 set viewer_size {575 360}

 # SMTP Server
 set smtp_server 192.168.100.50

 # Security and session management
 if {[catch {Doc_Cookie project_session}] > 0} {

     # There's no session cookie

     if {[ncgi::value username] != "" && [ncgi::value password] != ""} {

         # The user is trying to login, so create a client-side cookie containing
         # their session ID.
         Doc_SetCookie -name project_session -value [Session_Create project_session]

         # This is where we'll need to validate the username/email and password and
         # act accordingly

     } elseif {[ncgi::value username] != "" && [ncgi::value email] != ""} {

         # The user needs their password emailed to them

         # This is where we'll want to verify that the email address exists
         # in the user database, and act accordingly

     } else {

         # Hmmmm...I'm not sure what the user is trying to do, send them
         # to the login page
         Doc_Redirect /
     }

 } else {

     # User already has an active session, so do nothing for now
 }

See also:


LV Has anyone played with invoking Java objects from a .tml file? Someone stopped by this morning talking to me about ColdFusion vs Java servlets vs Tcl on the desktop, and they indicated that they were not considering Tcl on the back-end. They need to be able to interact with their business login which is in EJB beans. I won't be able to convince them otherwise, but I just thought I would check to see what people had tried along these lines.


Category TclHttpd