View on
MetaCPAN is shutting down
For details read Perl NOC. After June 25th this page will redirect to
Marc - Sebastian Lucksch > Dotiac-addon-html_template-0.4 > Dotiac::DTL::Addon::html_template_pure



Annotate this POD

View/Report Bugs
Module Version: 0.3   Source  


Dotiac::DTL::Addon::html_template_pure - Render pure HTML::Template in Dotiac::DTL


Load in Perl file for all templates:

        use Dotiac::DTL::Addon::html_template_pure;

Unload again:

        no Dotiac::DTL::Addon::html_template_pure;      

Load from a Dotiac::DTL-template (only Dotiac::DTL 0.8 and up)

        {% load html_template_pure %}<TMPL_VAR NaME=Foo>....

You also might want make the whole thing case insensitive if the HTML::Template template's need it.

        use Dotiac::DTL::Addon::html_template_pure;
        use Dotiac::DTL::Addon::case_insensitive;

or in the template ( > Dotiac::DTL 0.8 ):

        {% load html_template_pure case_insensitive %}<TMPL_VAR NaME=Foo>....


via CPAN:

        perl -MCPAN -e "install Dotiac::DTL::Addon::html_template"

or get it from, extract it and then run in the extracted folder:

        perl Makefile.PL
        make test
        make install


This makes Dotiac::DTL render templates written for HTML::Template. There are three ways to do this:


This exchanges the parser of Dotiac::DTL with one that can read HTML::Template templates.

It can't render Django Templates anymore, so those will not work.


This also exchanges the parser, but with one that can read both Django and HTML::Template templates.

This way HTML::Template templates can import/extend Django templates and be imported/extended from them.

This means currently working HTML::Template templates can be extended with some Django/Dotiac tags and it will still work like expected

        <!-- Large web project -->
        <TMPL_IF time><div id="time">{# <TMPL_VAR time> Now Django #}{{ time|date:"Y-m-d H:M" }}</TMPL_IF>

But there will be a problem if the HTML::Template template contains not Django {{, {% or {# tags, but this is rarely the case.


This replaces HTML::Template and converts the templates before giving them to Dotiac::DTL. It can work with both pure and combined Django/HTML::Template templates.

So even here Django and HTML::Template tags can be mixed, and there is just one different line in the script

        # use HTML::Template # Not anymore
        use Dotiac::DTL::Addon::html_template::Convert qw/combine/ #Now using Dotiac

See Dotiac::DTL::Addon::html_template::Convert


Same as Convert, behaves like HTML::Template to the script, but uses Dotiac::DTL internally. Also supports mixed templates.

This is faster than Convert when using scalarrefs and such as template data.

Convert on the other hand is more stable with filenames, Replace might get confused when using different options on the same template.

See Dotiac::DTL::Addon::html_template::Replace


Since Django has no concept of options to a template, there are a few HTML::Template options that can't be ignored:


This won't work at all, the templates will need to have the filter applied beforehand. There are a lot of things that HTML::Template requires a filter for, but Django supports in a different way, for example: Includes from variables, n-sstage templating (Dotiac::DTL::Addon::unparsed).


There is also no corresponding thing in Dotiac, but there is an easy solution that almost does the same thing (at least for CGI):

        my $template=Dotiac::DTL->new(...);
        $cgi=new CGI;
        #And then in the template:
        Hello, <TMPL_VAR>

It this won't work you need (because of existsing templates), do this:

        # $obj is the associate object.
        foreach my $p ($obj->param()) {
        # In the template:
        Hello, <TMPL_VAR name>


This option defaults to off in HTML::Template, but in Django it defaults to on.

This is quite bad for most templates, so you can use the case_insensitive addon from CPAN for this. (It should already be installed when this module is installed):

In the perl script that calls it:

        use Dotiac::DTL::Addon::case_insensitive;

In the template (before any {% load html_template_pure %}) with Dotiac::DTL 0.8 and up:

        {% load case_insensitive %}

But remember, this makes Dotiac::DTL slower, so this should be avoided and all variables should be in the right case.


This one defaults to off in HTML::Template, but is set to on here, because it probably won't disrupt any templates.

It can be set to off if there are some problems:

        use Dotiac::DTL::Addon::html_template_pure loop_context_vars=>0;


This one defaults to off in HTML::Template, but it is also set to on here, because it probably won't disrupt any templates.

It can be set to off if there are some problems:

        use Dotiac::DTL::Addon::html_template_pure global_vars=>0;


This is set to off in HTML::Template (which is not that good), but set to HTML in Django. Therefore this parser has to fiddle about with it a lot.

        use Dotiac::DTL::Addon::html_template_pure default_escape=>"HTML";
        use Dotiac::DTL::Addon::html_template_pure default_escape=>"JS";
        use Dotiac::DTL::Addon::html_template_pure default_escape=>"URL";

Combine options

        use Dotiac::DTL::Addon::html_template_pure global_vars=>0, loop_context_vars=>0, default_escape=>"HTML";

Setting options during runtime:

Options are save in %Dotiac::DTL::Addon::html_template_pure::OPTIONS (no matter if you use Dotiac::DTL::Addon::html_template_pure or Dotiac::DTL::Addon::html_template).

Changes are only applied to the following new() calls or included templates during print().

        $Dotiac::DTL::Addon::html_template_pure::OPTIONS{default_escape}="" #off


Note: Changing options for the same template might not work because of the caching routines.

It works fine for different templates.

Also note: Once a template is compiled, these options are ignored. In fact the whole module wouldn't be needed anymore. (Unless there is a {% load html_template(_pure) %} in there)


It is possible for Django tags close Html::Template tags and reverse, but it is not very pretty:

        <h1>My posts</h1>
        <TMPL_LOOP posts>
                {% if title %}
                        {{ title }}
                <!-- TMPL_ELSE -->
                        A post
                {{ text|linebreaksbr}}
        {% endimportloop %}

But sometimes it might be useful to add an {% empty %} tag to an existing template:

        Updated on :
        <TMPL_LOOP updated>
                {{ time|date }}
        {% empty %}


Please report any bugs or feature requests to


Dotiac::DTL, Dotiac::DTL::Addon,,


Marc-Sebastian Lucksch

syntax highlighting: