Kaelin Colclasure

NAME

HTML::Subtext - Perform text substitutions on an HTML template

SYNOPSIS

  use HTML::Subtext;
  %context = ( ... ); # Hash of names to substitution text
  $p = HTML::Subtext->new('CONTEXT' => \%context);
  $p->parse_file("template.html");

DESCRIPTION

HTML::Subtext is a package for performing text substitutions on a specially formatted HTML template. The template uses normal HTML markup, but includes links of the form:

  <a href="subtext:foo/bar">This text will be replaced</a>

The URI in this link tells HTML::Subtext to check in the provided hash 'CONTEXT' for a key named 'foo/bar'. If this lookup succeeds in producing a string value, the text in the body of the link is replaced by that value.

EXAMPLES

This example performs substitutions into a template embedded into the Perl code as a here-document.

  use HTML::Subtext;
  
  %context = (
    'author/name' => 'Kaelin Colclasure',
    'author/email' => '<a href="mailto:kaelin@acm.org">kaelin@acm.org</a>'
  );
  
  $p = HTML::Subtext->new('CONTEXT' => \%context);
  $p->parse(<<EOT);
  <html><head><title>example</title></head><body>
  <a href=\"subtext:author/name\">Author's name here</a>
  <a href=\"subtext:author/email\">mailto: link here</a>
  </body></html>
  EOT

When run, the example produces the following output:

  <html><head><title>example</title></head><body>
  Kaelin Colclasure
  <a href="mailto:kaelin@acm.org">kaelin@acm.org</a>
  </body></html>

SEE ALSO

HTML::Filter, HTML::Parser

COPYRIGHT

Copyright 1999 Kaelin Colclasure.

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.