.tcl-style dynamic pages

http://naviserver.sourceforge.net/ns_logobig.gif

MainSource Code Downloads API Documentation Mailing Lists Bugs Developers


Support for .tcl-style dynamic pages

file.tcl is responsible for setting up all that's necessary for allowing you to use TCL files in your webserver directories.

Notice the entries in your sample-config.tcl configuration file:

  ns_section "ns/server/${servername}"
  ns_param   directoryfile   $directoryfile
  ns_param   pageroot        $serverdir/$pageroot
  ns_param   enabletclpages  false     ;# Parse *.tcl files in pageroot.
  ns_param   filecachesize   5000000   

The default is to not enable TCL pages.

If you set this to true this is what happens at server startup when file.tcl is sourced:

  1. The procedure ns_sourceproc is registered for the HTTP methods GET, POST and HEAD via ns_register_proc.
  2. Caching TCL-bytecode is supported:
  3. It looks for a configuration parameter filecachesize for the size of the cache.(You can add this to the config lines above)
  4. If not found the Cache Size defaults to nearly 5 MB
  5. A procedure ns_sourcefile is created with special code to handle caching and flushing.
  6. The procedure ns_sourceproc works as follows:
  7. If a requested file does not exist on the filesystem it returns via ns_returnnotfound
  8. An existing TCL file is sourced via ns_sourcefile (see above)
  9. If a custom error page exists it is sourced. That error page is responsible for handling the error, e.g. communication with a user.

Setting up a TCL error page

Similar to the ADP error page example in your sample-config.tcl file you could setup a TCL error page:

 ns_section "ns/server/${servername}/tcl"
 ns_param   errorPage   ${serverdir}/${pageroot}/errorpage.tcl ;# TCL error page