From: Ash Berlin Date: Mon, 20 Nov 2006 18:33:03 +0000 (+0000) Subject: Changed docs to use view('TT')->render not $c->subreq X-Git-Tag: v0.09~18 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=catagits%2FCatalyst-Plugin-Email.git;a=commitdiff_plain;h=ea0b5860208deea274e77f5dddab1125a121182b Changed docs to use view('TT')->render not $c->subreq --- diff --git a/Changes b/Changes index 8009c73..361b889 100644 --- a/Changes +++ b/Changes @@ -3,7 +3,8 @@ Revision history for Perl extension Catalyst::Plugin::Email. 0.06 - Added more extensive docs on config and usage. (Carl Franks) - - Make it croak if recipient is empty. + - Make it croak if recipient is empty. + - Change docs to use ->render not subreq 0.05 Thu Nov 17 22:00:00 2005 - Added docs on sending email using a TT template. diff --git a/Email.pm b/Email.pm index 7945e66..5f3f34a 100644 --- a/Email.pm +++ b/Email.pm @@ -64,7 +64,10 @@ C. To => 'me@localhost', Subject => 'A TT Email', ], - body => $c->subreq( '/render_email' ), + body => $c->view('TT')->render($c, 'email.tt', { + additional_template_paths => [ $c->config->{root} . '/email_templates'], + } + ), ); To send a multipart message, include a C argument containing an @@ -85,7 +88,11 @@ arrayref of Email::MIME objects. disposition => 'attachment', charset => 'US-ASCII', }, - body => $c->subreq( '/render_email' ), + body => $c->view('TT')->render($c, 'email.tt', { + additional_template_paths => [ $c->config->{root} . '/email_templates'], + names => [qw/foo bar baz/] + } + ), ), ); @@ -118,13 +125,13 @@ sub email { =head1 USING WITH A VIEW A common practice is to handle emails using the same template language used -for HTML pages. This can be accomplished by pairing this plugin with -L. +for HTML pages. This is best accomplished by capturing the output from the +template. For TT this is done using the C method as described in +L. Here is a short example of rendering an email from a Template Toolkit source -file. The call to $c->subreq makes an internal call to the render_email -method just like an external call from a browser. The request will pass -through the end method to be processed by your View class. +file. For more information on render (or how to do this with a view other +than TT, consult the docs for your view) sub send_email : Local { my ( $self, $c ) = @_; @@ -134,20 +141,15 @@ through the end method to be processed by your View class. To => 'me@localhost', Subject => 'A TT Email', ], - body => $c->subreq( '/render_email' ), + body => $c->view('TT')->render('email.tt', + { additional_template_paths => [ $c->config->{root} . '/email_templates'], + names => [ qw/andyg sri mst ash/ ], + } ), + ); # redirect or display a message } - - sub render_email : Local { - my ( $self, $c ) = @_; - - $c->stash( - names => [ qw/andyg sri mst/ ], - template => 'email.tt', - ); - } - + And the template: [%- FOREACH name IN names -%] @@ -163,6 +165,7 @@ Output: Hi, andyg! Hi, sri! Hi, mst! + Hi, ash! -- Regards, @@ -170,8 +173,7 @@ Output: =head1 SEE ALSO -L, L, L, -L +L, L, L, L =head1 AUTHOR