NAME
Catalyst::View::Xslate - Text::Xslate View Class
SYNOPSIS
VIEW CONFIGURATION
You may specify the following configuration items in from your config file or directly on the view object.
catalyst_var
The name used to refer to the Catalyst app object in the template
template_extension
The suffix used to auto generate the template name from the action name (when you do not explicitly specify the template filename);
Do not confuse this with the suffix
option, which is passed directly to the Text::Xslate object instance. This option works on the filename used for the initial request, while suffix
controls what cascade
and include
directives do inside Text::Xslate.
content_charset
The charset used to output the response body. The value defaults to 'UTF-8'.
Text::Xslate CONFIGURATION
The following parameters are passed to the Text::Xslate constructor. When reset during the life cyle of the Catalyst app, these parameters will cause the previously created underlying Text::Xslate object to be cleared
path
cache_dir
cache
header
escape
footer
function
input_layer
module
syntax
verbose
suffix
Use this to enable TT2 compatible variable methods via Text::Xslate::Bridge::TT2 or Text::Xslate::Bridge::TT2Like
package
MyApp::View::Xslate;
use
Moose;
has
'+module'
=> (
default
=>
sub
{ [
'Text::Xslate::Bridge::TT2Like'
] }
);
expose_methods
Use this option to specify methods from the View object to be exposed in the template. For example, if you have the following View:
package
MyApp::View::Xslate;
use
Moose;
sub
foo {
my
(
$self
,
$c
,
@args
) =
@_
;
return
...;
# do something with $self, $c, @args
}
then by setting expose_methods, you will be able to use $foo() as a function in the template:
<:
$foo
(
"a"
,
"b"
,
"c"
)
# calls $view->foo( $c, "a", "b", "c" ) :>
expose_methods
takes either a list of method names to expose, or a hash reference, in order to alias it differently in the template.
MyApp::View::Xslate->new(
# exposes foo(), bar(), baz() in the template
expose_methods
=> [
qw(foo bar baz)
]
);
MyApp::View::Xslate->new(
# exposes $foo_alias(), $bar_alias(), $baz_alias() in the template,
# but they will in turn call foo(), bar(), baz(), on the view object.
expose_methods
=> {
foo
=>
"foo_alias"
,
bar
=>
"bar_alias"
,
baz
=>
"baz_alias"
,
}
);
METHODS
$view-
process($c)>
Called by Catalyst.
$view-
render($c, $template, \%vars)>
Renders the given $template
using variables \%vars.
$template
can be a template file name, or a scalar reference to a template string.
$view
->render(
$c
,
"/path/to/a/template.tx"
, \
%vars
);
$view
->render(
$c
, \
'This is a xslate template!'
, \
%vars
);
AUTHOR
Copyright (c) 2010 Daisuke Maki <daisuke@endeworks.jp>
LICENSE
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
See http://www.perl.com/perl/misc/Artistic.html