|
NAMECatalyst::View::TT::Alloy - Template::Alloy (TT) View ClassVERSIONversion 0.00007SYNOPSIS# use the helper to create your View myapp_create.pl view TT::Alloy TT::Alloy# configure in myapp.yml 'View::TT::Alloy': INCLUDE_PATH: - __path_to(root/src)__ - __path_to(root/lib)__ PRE_PROCESS: 'config/main' WRAPPER: 'site/wrapper' # optional TEMPLATE_EXTENSION: '.tt' CATALYST_VAR: 'Catalyst' # example render view in lib/MyApp/Controller/Root.pm sub default : Private { my ( $self, $c ) = @_; $c->stash->{template} = 'message.tt2'; $c->stash->{message} = 'Hello World!'; return; } sub end : ActionClass('RenderView') { } # access variables from template The message is: [% message %]. # example when CATALYST_VAR is set to 'Catalyst' Context is [% Catalyst %] The base is [% Catalyst.req.base %] The name is [% Catalyst.config.name %] # example when CATALYST_VAR isn't set Context is [% c %] The base is [% base %] The name is [% name %] DESCRIPTIONThis is the Catalyst view for the TT emulator Template::Alloy.Your application should define a view class which is a subclass of this module. The easiest way to achieve this is using "script/myapp_create.pl" (replacing "myapp" with the name of your application). $ script/myapp_create.pl view TT::Alloy TT::Alloy You can either manually forward to the "TT::Alloy" as normal, or use Catalyst::Action::RenderView to do it for you. # In MyApp::Controller::Root sub end : ActionClass('RenderView') { } RATIONALTemplate::Alloy is a pure-perl module which emulates most common features of TT, and in some cases is faster too. See Template::Alloy::TT for details of which features are missing.Catalyst::View::TT::Alloy is generally compatible with Catalyst::View::TT. The "TIMER" configuration option isn't supported, and the "paths()" alias to "include_path()" has been removed. Although Template::Alloy emulates several other templating modules, the interface differs for each one. For this reason, this module only provides the TT interface. DYNAMIC INCLUDE_PATHSometimes it is desirable to modify INCLUDE_PATH for your templates at run time.Additional paths can be added to the start of INCLUDE_PATH via the stash as follows: $c->stash->{additional_template_paths} = [$c->config->{root} . '/test_include_path']; If you need to add paths to the end of INCLUDE_PATH, there is also an include_path() accessor available: push( @{ $c->view('TT')->include_path }, qw/path/ ); Note that if you use include_path() to add extra paths to INCLUDE_PATH, you MUST check for duplicate paths. Without such checking, the above code will add "path" to INCLUDE_PATH at every request, causing a memory leak. A safer approach is to use include_path() to overwrite the array of paths rather than adding to it. This eliminates both the need to perform duplicate checking and the chance of a memory leak: $c->view('TT')->include_path([ qw/ path another_path / ]); If you are calling "render" directly then you can specify dynamic paths by having a "additional_template_paths" key with a value of additonal directories to search. See "CAPTURING TEMPLATE OUTPUT" for an example showing this. RENDERING VIEWSThe view plugin renders the template specified in the "template" item in the stash.sub message : Global { my ( $self, $c ) = @_; $c->stash->{template} = 'message.tt2'; $c->forward('MyApp::View::TT::Alloy'); } If "template" isn't defined, then it builds the filename from "Catalyst/action" and the "TEMPLATE_EXTENSION" config setting. In the above example, this would be "message". The items defined in the stash are passed to Template::Alloy for use as template variables. sub default : Private { my ( $self, $c ) = @_; $c->stash->{template} = 'message.tt2'; $c->stash->{message} = 'Hello World!'; $c->forward('MyApp::View::TT::Alloy'); } A number of other template variables are also added: c A reference to the context object, $c base The URL base, from $c->req->base() name The application name, from $c->config->{ name } These can be accessed from the template in the usual way: <message.tt2>: The message is: [% message %] The base is [% base %] The name is [% name %] The output generated by the template is stored in "$c->response->body". CAPTURING TEMPLATE OUTPUTIf you wish to use the output of a template for some other purpose than displaying in the response, e.g. for sending an email, this is possible using Catalyst::Plugin::Email and the render method:sub send_email : Local { my ($self, $c) = @_; $c->email( header => [ To => 'me@localhost', Subject => 'A TT Email', ], body => $c->view('TT::Alloy')->render($c, 'email.tt', { additional_template_paths => [ $c->config->{root} . '/email_templates'], email_tmpl_param1 => 'foo' } ), ); # Redirect or display a message } METHODS
HELPERSThe Catalyst::Helper::View::TT::Alloy module is provided to create your view module. It is invoked by the "myapp_create.pl" script:$ script/myapp_create.pl view TT::Alloy TT::Alloy SUPPORTCatalyst Mailing List:<http://lists.rawmode.org/mailman/listinfo/catalyst> GIT REPOSITORY<https://github.com/djzort/Catalyst-View-TT-Alloy>SEE ALSOCatalyst, Catalyst::Helper::View::TT::Alloy, Template::AlloyAUTHORSCarl Franks, "cfranks@cpan.org"Based on the code of "Catalyst::View::TT", by Sebastian Riedel, "sri@cpan.org" Marcus Ramberg, "mramberg@cpan.org" Jesse Sheidlower, "jester@panix.com" Andy Wardley, "abw@cpan.org" CONTRIBUTORSMoritz Onken, "onken@netcubed.de"Dean Hamstead "dean@bytefoundry.com.au" COPYRIGHTThis program is free software, you can redistribute it and/or modify it under the same terms as Perl itself.
Visit the GSP FreeBSD Man Page Interface. |