NAME

Tenjin::Engine - Tenjin's engine.

SYNOPSIS

use Tenjin;

$Tenjin::USE_STRICT = 1;	# use strict in the embedded Perl inside
				# your templates. Recommended, but not used
				# by default.

$Tenjin::ENCODING = "utf8";	# set the encoding of your template files
				# to utf8. This is the default encoding used
				# so there's no need to do this if your
				# templates really are utf8.

my $engine = new Tenjin::Engine(\%options);
my $context = { title => 'Tenjin Example', items => [qw/AAA BBB CCC/] };
my $filename = 'file.html';
my $output = $engine->render($filename, $context);
print $output;

METHODS

new \%options

This creates a new instant of Tenjin::Engine. \%options is a hash-ref containing Tenjin's configuration options:

  • path - Array-ref of filesystem paths where templates will be searched

  • prefix - A string that will be automatically prepended to template names when searching for them in the path. Empty by default.

  • postfix - The default extension to be automtically appended to template names when searching for them in the path. Don't forget to include the dot, such as '.html'. Empty by default.

  • cache - If set to 1 (the default), compiled templates will be cached on the filesystem.

  • preprocess - Enable template preprocessing (turned off by default). Only use if you're actually using any preprocessed Perl code in your templates.

  • layout - Name of a layout template that can be optionally used. If set, templates will be automatically inserted into the layout template, in the location where you use [== $_content ==].

  • strict - Another way to make Tenjin use strict on embedded Perl code (turned off by default).

  • encoding - Another way to set the encoding of your template files (set to utf8 by default).

render $tmpl_name, [\%context, $layout]

Renders a template whose name is identified by $tmpl_name. Remember that a prefix and a postfix might be added if they where set when creating the Tenjin::Engine instant.

$context is a hash-ref containing the variables that will be available for usage inside the templates. So, for example, if your \%context is { message => 'Hi there }, then you can use $message inside your templates.

$layout is a flag denoting whether or not to render this template into the layout template there was set when creating the Tenjin::Engine instant.

SEE ALSO

Tenjin.

AUTHOR

Tenjin is developed by Makoto Kuwata at http://www.kuwata-lab.com/tenjin/. Version 0.03 was tidied and CPANized from the original 0.0.2 source by Ido Perelmutter <ido50@yahoo.com>.

COPYRIGHT & LICENSE

Tenjin is licensed under the MIT license.

Copyright (c) 2007-2009 the aforementioned authors.

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.