Skip to content
This repository


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

JavaScript parser for HTML::Template templates

branch: master

Fetching latest commit…


Cannot retrieve the latest commit at this time

Octocat-spinner-32 example
Octocat-spinner-32 README
Octocat-spinner-32 perltemplates.js
Octocat-spinner-32 perltemplates.min.js

    Allows you to reuse your HTML::Template templates in your JavaScript code.

    I originally wrote this code to facilitate the principles of DRY and
    progressive enhancement in our AJAX applications. 
    At first I adopted the EJS library( which was aimed
    at Ruby on Rails developers, but found myself constantly rewriting
    my HTML::Template files to fit the Rails template syntax. Changes in
    the markup or presentation logic in one template had to be duplicated
    across our two templates.
    Using PerlTemplates, we only to keep one template. It has also
    simplified the AJAX handling logic in our perl scripts. We can take code 
    that looks like this:
        my $template = HTML::Template->new('/path/to/search/results.tmpl');
        $template->param(%values); # where values contains the template data structure
        print CGI->header, $template->output();
    Into this:
            print CGI->header, JSON->new->encode(%values);        
            my $template = HTML::Template->new('/path/to/search/results.tmpl');
            print CGI->header, $template->output();
    And the JavaScript to support this (with jQuery) becomes:
        $.getJSON('/search/results', function(json_data) {
            var tmpl = new PerlTemplates({url:'results.tmpl', data: json_data, target: 'search-results'});
    And now we have a both an AJAX and non-JavaScript version of our search results script.


    * Currently, most of the configuration options available to HTML::Template constructor 
    are NOT supported. 
    * Your templates must be accessible over HTTP. 


    The concept of converting a template into a 'process' function 
    was taken from the EmbeddedJS library at
Something went wrong with that request. Please try again.