NAME
HTML::Template::Bundle - Use everything available from HTML::Template
SYNOPSIS
use HTML::Template::Bundle;
my $template = HTML::Template::Bundle->new(filename => 'foo.tmpl');
$template->param(...);
print $template->output();
or
my $template = HTML::Template::Bundle->new_bundle(filename => 'foo.tmpl');
If you prefer a shrink-wrapped version.
use HTML::Template::Bundle;
my $content = tmpl_render('foo.tmpl',
....
));
print $content;
DESCRIPTION
This module provides an extension to HTML::Template (and HTML::Template::Expr) which enables all of the useful feature requests made over the years.
Basically all of the documentation for the original HTML::Template, applies here too. That said, there are a lot of enhancements, so you will want to familiarise yourself with the new features, thus perldoc HTML::Template
and perldoc HTML::Template::Expr
contain the updated docs. You will also want to read up on HTML::Template::Bundle
(aka this document), HTML::Template::Filters
, HTML::Template::ESCAPE
and HTML::Template::Preload
.
NEW TAGS
TMPL_SET
<TMPL_SET some_VARIABLE_nAme="some value">
Does the equivalent of $ht->param(some_VARIABLE_nAme => "some value"), but from within the template.
METHODS
new()
Call new() to create a new Bundle instance; this instance doesn't have any HTML::Template options altered, so it its pimarily used as a drop-in replacement for existing code.
new_bundle()
Call new_bundle() enable most the new features provided by the HTML::Template enhancements and by the H::T::Bundle package.
These options are enabled as defaults:
die_on_bad_params => 0
die_on_unset_params => 1
structure_vars => 1
loop_context_vars => 1
intrinsic_vars => 1
recursive_templates => -1
strict => 0
filters =>
HT_FILTER_ALLOW_TRAILING_SLASH
HT_FILTER_SSI_INCLUDE_VIRTUAL
HT_FILTER_PERCENT_VARIABLES
HT_FILTER_TMPL_CONSTANT
HT_FILTER_TMPL_COMMENT
HT_FILTER_TMPL_FIXME
HT_FILTER_TMPL_JOIN
The DEBUG environmental variable is used to determine the current build environment, resulting in these defaults:
filters =>
$DEBUG ? HT_FILTER_STRIP_TMPL_NEWLINE_WHITESPACE : HT_FILTER_STRIP_REDUNDANT
Note that since H::T filters are stacked, the filters listed above are executed in that order.
tmpl_render
To simplify use of H::T::B features, we default-export a function which you can use for simple CGI or batch processing. Use it like:
tmpl_render('blah.tmpl','blah.html',
var => 'val',
...
);
or
my $content = tmpl_render('blah.html,
var => 'val',
...
);
Note that internally it new_bundle(); if you require a differing set of options, you will need to call new() as appropriate.
OPTIONS
Defaults
All existing options are passed directly to H::T, except that we enable the extended_syntax option so that we can make use of TMPL_SET, etc. Also note that H::T::B is a sub-class of H::T::E so global_vars is enabled by default.
New Options
- env_variables
-
Automatically define environmental variables as params. Note that case is preserved, as most environments will support mixed-case variables.
If this value is a string, it will be used for the prefix - otherwise 'ENV' is used. If 'structure_vars' is enabled, dotted-notation is used as the seperator - otherwise an underscore is used.
MOTIVATION
I wanted to use all of the HTML::Template features, without having to always write lots of code to make H::T sane. And I didn't particularly like using Template::Toolkit due to its quirks... and it is too much like PHP...
So as written in the HTML::Template::Expr perldoc:
If you don't like it, don't use this module. Keep using plain ol' HTML::Template - I know I will!
MOD_PERL TIP
Both HTML::Template and HTML::Template::Expr recommend some various tips when running under mod_perl. H::T::Preload simplifies this.
CAVEATS
The HTML::Template defaults for this module, differ than those for HTML::Template.... be aware...
BUGS
I am aware of no bugs - but I do know that some test cases arn't covered.
You can still email me directly if you find any.
CREDITS
Sam Tregar for the HTML::Template and H::T::Expr modules.
Ideas from the H::T mailing list.
Me.
Thanks!
AUTHOR
Mathew Robertson <mathew@users.sf.net>
LICENSE
Liscense is the same as that used by HTML::Template.