Patches for HTML::Template 2.5

Version 2.5.4, Tue Jan 13 13:46:25 EST 2004
HTML::Template is a powerful perl module for you to use HTML templates in your CGI/Mod-Perl scripts; and it's written by Sam Tregar. Here are some changes I made while using this module for my projects. You can get the original module from CPAN or here. The patch is available here. Hope these patches will be useful for other people, but it comes with no warranty or support.

List of Changes:

  1. Add extended expression support without impact on speed
            <TMPL_IF EXPR="item ne 'pizza' && price != 0.99">
                I got <TMPL_VAR NAME="item"> for
                <TMPL_VAR "price * count + 0.5"> dollars.
            <TMPL_ELSE>
                gee, free pizza!
            </TMPL_IF>
  2. Clean up global_vars implementation
  3. Add a new way to access outside variables without global_vars
            This is a normal variable: <TMPL_VAR NAME="NORMAL">.<P>
            <TMPL_LOOP NAME=FROOT_LOOP>
               Use it inside the loop: <TMPL_VAR NAME="::NORMAL"><P>
            </TMPL_LOOP>
  4. TMPL_VAR can now have a default value
            <TMPL_VAR NAME="PARAMETER_NAME" DEFAULT="default value">
  5. Add TMPL_DEF tag for defining new parameters with default values. They can be used by designers to pass parameters back to your script, for example, in a loop.
            <TMPL_DEF NAME="NAME" VALUE="value">
  6. Add __counter__ and __count__ to loops
             <TMPL_VAR NAME="__counter__">-th record in the loop 
                  with <TMPL_VAR NAME="__count__"> records.
  7. Add 'ESCAPE=SQL' to TMPL_VARs and 'escape=' global options
  8. Extended expressions are tagged with their MD5s, to make them suitable for saving in XML format.
  9. Add register_function() to link a given function name to a subrountine.
  10. Add scalar_cache option for caching to a scalar ref which can be stored and fetched from a DB.
  11. Add TMPL_ELSIF, based on a patch by Mathew Robertson <mathew.robertson@redsheriff.com>.
Please read the pod for details.

Have fun!
Yunliang Yu <yu at math.duke.edu>