NaviServer - programmable web server


[ Main Table Of Contents | Table Of Contents | Keyword Index ]

Support for .tcl-style dynamic pages(n) 4.99.5 manual "NaviServer Built-in Commands"

Name

Support for .tcl-style dynamic pages - Support for .tcl-style dynamic pages

Table Of Contents

Description

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   enabletclpages  false         ;# Parse *.tcl files in pageroot.

The default is to not enable TCL pages.

If you set first option 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. The procedure ns_sourceproc works as follows:

    1. If a requested file does not exist on the filesystem it returns via ns_returnnotfound

    2. An existing TCL file is sourced via ns_sourcefile (see above)

    3. 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

Support for .tcl-style dynamic pages via ADP engine

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

See Also

nsd

Keywords

NaviServer