tcl-lib-file - Support for .tcl-style dynamic pages
When a client requests a page, the page can be a static or dynamic, where the latter means that the content is computed at the time it is served. The dynamic content can be provided as .adp files or via .tcl files.
By default Tcl pages are not enabled, but can be enabled over the configuration file of NaviServer. Notice the entries in your sample-config.tcl configuration file:
ns_section "ns/server/${servername}" ns_param enabletclpages false ;# Parse *.tcl files in pageroot.
If you set first option to true this is what happens at server startup when file.tcl is sourced:
The procedure ns_sourceproc is registered for the HTTP methods GET, POST and HEAD via ns_register_proc.
The procedure ns_sourceproc works as follows:
If a requested file does not exist on the filesystem it returns via ns_returnnotfound
An existing TCL file is sourced via ns_sourcefile (see above)
If a custom error page exists it is sourced. That error page is responsible for handling the error, e.g. communication with a user.
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
Another way to support .tcl pages to use ADP engine to process .tcl file as ADP pages. the engine will source Tcl file and wrap it as <% ns_adp_include filename %>, then compiled it as regular ADP page. If caching enabled, the tcl file will be compiled as Tcl proc into bytecode. Using ADP engine is faster than using file.tcl based approach.
ns_section "ns/server/${servername}/adp" ns_param enabletclpages false ;# Parse *.tcl files in pageroot. ns_param errorpage ${serverdir}/${pageroot}/errorpage.adp ;# ADP error page