Version 7 of TclHttpd: The .tml File

Updated 2004-04-15 21:35:06

The .tml file is a good place to put variables and procedures that are used by all templates in the directory. 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
         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:


Category TclHttpd