# Templates are HTML files with special tags in braces {tag}. display()
# will take a template HTML file and hashes to replace the tags and
# generate HTML output and then send it to the browser. save() does the
# same work but saves the template to disk. Normally values are scalars
# that replace tags in the HTML. If the value is code, the method that code
# points to is an iterator that returns a hash for a repetitive HTML segment.
# The segment is bounded by the tag and a closing tag {/sameName}.
# The special tag {NEXT} can be used to have the iterator called more
# than once for the segment (as in 3 images per line). The iterator returns
# undef or 0 when there are no more elements.
# ~/blah => /art/templates/blah
# /blah => $ENV{DOCUMENT_ROOT}/blah
# <!--{tag}--> will drop the comment, as will <!--{tag}...{/tag}-->
$template = '~/display.template'
HTML::display( $template, NAME => 'fred', CGI::commands());
HTML::save( $fileName, $template, NAME => 'fred', CGI::commands());
# line items are between {lineItem}...{/lineItem} across multiple lines
# {NEXT} allows multiple line items in replacement text
my @items = ((a=>1,b=>2),(a=>3,b=>4)(a=>5,b=>6));
sub lineItems { return undef if not @items; return shift(@items); }
HTML::display( $template, name => 'fred', lineItems => \&lineItems);