If you wish to use chtml markup in your CGI programs, but cannot make use of template files, you'll need to save your output to a temporary file and then have chtml postprocess that file. The postprocessor will output all the necessary CGI headers, so you just need to use exec
to call it.
The chtml postprocessor is available at /www/lib/chtml-postproc
, and takes a single argument of a file to run through chtml. If you use the filename of -
then the postprocessor will read the contents of the file from standard input (but note in some cases it's more efficient to write to a temporary file to avoid the extra process required to write to standard input). Note you must not pass any HTTP headers; they will be treated as HTML.
You can give optional arguments, also:
-r
-h
header-h
arguments may be specified.-d
dirThe chtml postprocessor will show a short error message if it is incorrectly invoked, and the HTML generated by your CGI will not be displayed, nor the original file removed.
As an example this shell CGI (source and raw output) will call the chtml postprocessor after creating a temporary file. Another version (with source and raw output) of the example writes to the postprocessor using standard input. Note that the file has many chtml directives in it. In addition, this script will set extra headers which, in this case, will be ignored by the browser.
Other things to note about the example:
-h
to specify headers is optional.-d
switch is used to set the pwd, since the temporary file is in a different directory than the files included by chtml.Since chtml date statements use the modify time of the html file for datestamps, you can control what date chtml thinks the original file was changed by setting the modify time on the file.