-
-
09 Jul 2013 21:29:15 UTC
- Distribution: Template-Swig
- Module version: 0.04
- Source (raw)
- Browse (raw)
- Changes
- How to Contribute
- Repository
- Issues
- Testers
- Kwalitee
Bus factor: 0- License: perl_5
- Activity
24 month- Tools
- Download (31.6KB)
- MetaCPAN Explorer
- Permissions
- Subscribe to distribution
- Permalinks
- This version
- Latest version
and 1 contributors-
David Chester
- Dependencies
- File::Slurp
- JSON::XS
- JavaScript::V8
- Test::Exception
- Test::More
- and possibly others
- Reverse dependencies
- CPAN Testers List
- Dependency graph
NAME
Template::Swig - Perl interface to Django-inspired Swig templating engine.
SYNOPSIS
my $swig = Template::Swig->new; $swig->compile('message', 'Welcome, {{name}}'); my $output = $swig->render('message', { name => 'Arthur' });
DESCRIPTION
Template::Swig uses JavaScript::V8 and Paul Armstrong's Swig templating engine to provide fast Django-inspired templating in a Perl context. Templates are compiled to JavaScript functions and stored in memory, then executed each time they're rendered.
Swig's feature list includes multiple inheritance, formatter and helper functions, macros, auto-escaping, and custom tags. See the Swig Documentation for more.
METHODS
new( template_dir => $path, extends_callback => sub { } )
Initialize a swig instance, given the following parameters
template_dir
Optional path where templates live
extends_callback
Optional callback to be run when Swig encounters an extends tag; receives filename and its encoding as parameters
compile($template_name, $swig_source)
Compile a template given, given a template name and swig template source as a string.
compile($file_name)
Will compile a file from the file system. In order for this to work an extends_callback, needs to be implemented.
render($template_name, $data)
Render a template, given a name and a reference to a hash of data to interpolate.
TEMPLATE EXAMPLES
Iterate through a list:
{% for image in images %} <img src="{{ image.src }}" width="{{ image.width }}" height="{{ image.height }}"> {% else %} <div class="message">No images to show</div> {% endfor %}
Custom helpers / filters:
{{ created|date('r') }}
Inheritance:
In main.html:
{% block 'greeting' %} Hi, there. {% endblock %}
In custom.html:
{% extends 'main.html' %} {% block 'greeting' %} Welcome, {{ name }} {% endblock %}
SEE ALSO
Dotiac::DTL, Text::Caml, Template::Toolkit
COPYRIGHT AND LICENSE
Copyright (c) 2012, David Chester
This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
Module Install Instructions
To install Template::Swig, copy and paste the appropriate command in to your terminal.
cpanm Template::Swig
perl -MCPAN -e shell install Template::Swig
For more information on module installation, please visit the detailed CPAN module installation guide.