Tenjin::Context - In charge of managing variables passed to Tenjin templates.


        # this module is used internally, but if you insist, it is
        # in charge of the context object:

        # in your templates (unnecessary, for illustration purposes):
        <title>[== $_context->{title} =]</title>
        # instead use:
        <title>[== $title =]</title>


This module is in charge of managing Perl variables that are passed to templates upon rendering for direct usage. The context object is simply a hash-ref of key-value pairs, which are made available for templates as "standalone variables" named for each key in the hash-ref.

This module is also in charge of the actual rendering of the templates, or more correctly, for evaluating the Perl code created from the templates, first integrating the context variables to them, and returning the rendered output.

Finally, this module makes the Tenjin utility methods of Tenjin::Util available natively inside templates. See Tenjin::Util for more info.


new( [\%vars] )

Constructs a new context object, which is basically a hash-ref of key-value pairs which are passed to templates as variables. If a $vars hash-ref is passed to the constructor, it will be augmented into the created object.

To illustrate the context object, suppose it looks like so:

                scalar          => 'I am a scalar',
                arrayref        => [qw/I am an array/],
                hashref =>      { i => 'am', a => 'hash-ref' },

Then the variables $scalar, $arrayref and $hashref will be available for direct usage inside your templates, and you can dereference the variables normally (i.e. @$arrayref and %$hashref).

evaluate( $script, $template_name )

This method receives a compiled template and actually performes the evaluation the renders it, then returning the rendered output. If Tenjin is configured to use strict, the script will be evaled under use strict.

to_func( $script, [$filename] )

This method receives the script created when reading a template and wraps it in a subroutine, evals it and returns the rendered output. This method is called when compiling the template.


This method is in charge of making all the key-value pairs of the context object available to templates directly by the key names. This is simply done by traversing the key-value pairs of the context object and adding an assignment line between a scalar variable named as the key and its appropriate value.


These methods are defined in Tenjin::Util and used here so they are made available natively inside templates. See Tenjin::Util for more information.

_p( $expr )

_P( $expr )

escape( $expr )

escape_xml( $expr )

unescape_xml( $expr )

encode_url( $url )

decode_url( $url )

checked( $expr )

selected( $expr )

disabled( $expr )

nl2br( $text )

text2html( $text )

tagattr( $name, $expr, [$value] )

tagattrs( %attrs )

new_cycle( @items )


Tenjin, Tenjin::Util, Tenjin::Template.


See Tenjin.