Using chtml to Filter Templates

If you wish to use chtml markup in Perl script, one way to do it is to use a template file. In this scenario, you define a file which has your chtml markup, but instead of reading the file directly, you get the filename by calling a chtml function. That filename will be appropriate for the current access class (so if your chtml markup defines a section to only be visible by UW users, that section won't be visible if the current connection is from outside UW). Your script must include the line:

use '/www/lib/chtml-template.pl';

and, assuming $tmpl is the absolute path to your template file, you can open the file for reading with something similar to:

my $file = chtml_procfile ($tmpl);
open F, "<$file"; 

chtml Filtering Example

As an example, this Perl script (source) takes the template file and substitutes a fixed string with the value of the host from which the connection was made.