httpd::subst(n) 1.0 "Tcl Web Server"

Name

httpd::subst - Basic substitution and templating facility

Table Of Contents

Synopsis

Description

The package httpd::subst provides a basic template facility for the parameterization of delivered pages. This is not the full Template Macro Language (TML). TML is provided by the package httpd::template instead.

Note: This package also provides a number of type-specific doc handlers which will be picked up and used automatically by package httpd::doc. This will work if and only if an appropriate file extension to mime type mapping was added to httpd::mtype during startup of the server. If a file "mime.types" is present in the server library directory (residence of all packages) it will be read automatically and used to set up a standard mapping to support the type specific handlers exported by this package.

Public API

Subst_ReturnFile sock path ?interp?

This command is a convenience wrapper around Subst_File. It runs the substitution process on the file path and returns the result directly to the request waiting on connection sock.

Subst_File path ?interp?

Runs the substitution process on the file path and returns the result as the result of the command. If an interpreter is specified it will be used as the substitution context. If no interpreter is specified the current interpreter will be used as the context. When doing the latter the configuration defined via Subst_Scope will also determine whether the current or global scope is used for the processing.

Subst_Scope scope

Globally declares which scope to use when processing a template. A value of 0 for scope means that the global namespace will be used as scope, anything else causes usage of the current (procedure-)local scope. Initially the package is set up to use the global namespace. This value is effective if and only if the current interpreter is used to process a template. When using a different interpreter the processing will always happen at the global scope.

Subst_Install proc

This command registers the command name proc as a postprocessor.

All such commands are run by the package in order of registration whenever a template was processed. The first postprocessor is called with the result of the substitution as its first and only argument. All others will be called with the result of the previously-run postprocessor. The result of the last postprocessor is returned as the result of the whole substitution process.

Errors in a postprocessor will cause the system to abort processing.

Doc_application/x-tcl-subst path suffix sock ?interp?

This command is a type-specific document handler for pages of mime-type application/x-tcl-subst and is called by the package httpd::doc. Simply invokes Subst_ReturnFile to handle the insertion of data into the template file at path.

Doc_application/x-tcl-auth path suffix sock

Like Doc_application/x-tcl-subst except that a basic authentication cookie is used to obtain session state, and the substitution process will be run in the session interpreter.

See Also

httpd, httpd::cgi, httpd::doc, httpd::session

Keywords

substitution, templates, web server