NaviServer - programmable web server

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

# tcl-lib-file(n) 4.99.8 manual "NaviServer Manual"

## Name

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

## Table Of Contents

## Description

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:

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

adp-overview, nsd

## Keywords

NaviServer, configuration