NAME
Dotiac::DTL::Addon::html_template::Convert - Convert HTML::Template to Dotiac::DTL
SYNOPSIS
#!/usr/bin/perl -w
use Dotiac::DTL::Addon::html_template::Convert;
# open the html template
my $template = HTML::Template->new(filename => 'test.tmpl');
# fill in some parameters
$template->param(HOME => $ENV{HOME});
$template->param(PATH => $ENV{PATH});
# send the obligatory Content-Type and print the template output
print "Content-Type: text/html\n\n", $template->output;
DESCRIPTION
Converts HTML::Template templates to Dotiac::DTL templates.
Just replace
use HTML::Template;
with use Dotiac::DTL::Addon::html_template::Convert;
or
use Dotiac::DTL::Addon::html_template::Convert qw/combine/;
in the script that calls that template.
Dotiac::DTL::Addon::html_template::Convert will then convert the template into Dotiac::DTL/Django template code and render it.
If the input is a filename, it will also save the converted versions under "FILENAME"+[+/-]+4 chars+".html" and won't reconvert as long as that file is there and not outdated.
When using mostly scalarrefs as data, "use Dotiac::DTL::Addon::html_template::Replace" is a better choice and faster.
The 4 chars save the options of the HTML::Template, cause different options of HTML::Template result in different compiled template.
The 4 Bytes in the new name:
- First: g or n
-
"g" stands for global_vars on, "n" for off.
- Second: i or s
-
"i" stands for case_insensitive, "c" for case_sensitive
- Third: l or c
-
"l" stands for "loop_context_var" on, "c" for clear loop ("loop_context_var" off)
- Last: j, h, u, o
-
Save the default escape status:
"j" for "JS", "h" for "HTML", "u" for "URL", o for "off"
For example: On all options to default, the flag will be "nico", all options on it will be "gslh"
combine
When set "combine" in the use statement, this module will allow combined Django and HTML::Template code:
Valid template:
{% if test or failed %}<TMPL_VAR test>{% endif %}
This is done by first converting HTML::Template code into Django template code and then parsing the whole thing again.
{% if test or failed %}{{ test }}{% endif %}
The flags will be added with a leading "+" instead of a "-".
What won't work
Some options are accepted (global_vars,filter,loop_context_vars,associate,case_sensitive) the others are ignored (caching).
Sadly, the params() call without arguments and query() won't work at all prior to Dotiac::DTL 0.8, since Dotiac::DTL doesn't really care for variables until it renders.
Compiling
There is one additional option to new():
compile
Instructs Dotiac::DTL to compile the template, only works with filenames
my $t=HTML::Template->new(filename=>"foo.html",compile=>1);
This will first translate to "foo.html[FLAGS].html" and then on the next run compile to "foo.html[FLAGS]..html.pm"
BUGS
Please report any bugs or feature requests to https://sourceforge.net/tracker2/?group_id=249411&atid=1126445
SEE ALSO
Dotiac::DTL, Dotiac::DTL::Addon, http://www.dotiac.com, http://www.djangoproject.com
AUTHOR
Marc-Sebastian Lucksch
perl@marc-s.de