The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.


Plift - HTML Template Engine + Custom HTML Elements


    use Plift;

    my $plift = Plift->new(
        path    => \@paths,                               # default ['.']
        plugins => [qw/ Script Blog Gallery GoogleMap /], # plugins not included

    my $tpl = $plift->template("index");

    # set render directives
        '#name' => 'fullname',
        '#contact' => [
            '.phone' => '',
            '.email' => ''

    # render render with data
    my $document = $tpl->render({

        fullname => 'Carlos Fernando Avila Gratz',
        contact => {
            phone => '+55 27 1234-5678',
            email => ''

    # print
    print $document->as_html;


Plift is a HTML template engine which enforces strict separation of business logic from the view. It is designer friendly, safe, extensible and fast enough to be used as a web request renderer. This engine tries to follow the principles described in the paper Enforcing Strict Model-View Separation in Template Engines by Terence Parr of University of San Francisco. The goal is to provide suficient power without providing constructs that allow separation violations.


This document is the reference for the Plift class. The manual pages (not yet complete) are:


Step-by-step intruduction to Plift. "Hello World" style.


Pure HTML5 template files makes everything easier to write and better to maintain. Designers can use their WYSIWYG editor, backend developers can unit test their element renderers.


Talks about the web framework that inspired Plift, and its 'View-First' approach to web request handling. (As opposed to the widespread 'Controller-First').


Explains how Plift is just an engine for reading/parsing HTML files, and dispaching subroutine handlers bound to XPath expressions. You will learn how to write your custom handlers using the same dispaching loop as the builtin handlers.



Arguments: \%parameters

Binds a handler to one or more html tags, attributes, or xpath expression. Valid parameters are:


Scalar or arrayref of HTML tags bound to this handler.


Scalar or arrayref of HTML attributes bound to this handler.


XPath expression matching the nodes bound this handler.

See Plift::Manual::CustomHandler.


    $context = $plift->template($template_name, \%options)

Creates a new Plift::Context instance, which will load, process and render template $template_name. See "at" in Plift::Context, "set" in Plift::Context and "render" in Plift::Context.


    $document = $plift->process($template_name, \%data, \@directives)

A shortcut method. A new context is created via "template", rendering directives are set via "at" in Plift::Context and finally the template is rendered via "render" in Plift::Context. Returns a XML::LibXML::jQuery object representing the final processed document.

    my %data = (
        fullname => 'John Doe',
        contact => {
            phone => 123,
            email => 'foo@example'

    my @directives =
        '#name' => 'fullname',
        '#name@title' => 'fullname',
        '#contact' => {
            'contact' => [
                '.phone' => 'phone',
                '.email' => 'email',

    my $document = $plift->process('index', \%data, \@directives);

    print $document->as_html;


    $html = $plift->render($template_name, \%data, \@directives)

A shortcut for $plift->process()->as_html.


    $plift = $plift->load_components(@components)

Loads one or more Plift components. For each component, we build a class name by prepending Plift:: to the component name, then load the class, instantiate a new object and call $component->register($self).

See Plift::Manual::CustomHandler.


This is a list of modules (that I know of) that pursue similar goals:


Probably one of the first to use (almost) valid html files as templates, and encourage less business logic to be embedded in the templates.


Perl implementation of Pure.js. This module inspired Plift's render directives.


Similar to Template::Pure, but the render directives points to the actual data values, instead of datapoints. Which IMHO makes the work harder.


Uses a XML specification format for the rendering directives. Has lots of other features.


Copyright (C) Carlos Fernando Avila Gratz.

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.


Carlos Fernando Avila Gratz <>