X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=Email.pm;fp=Email.pm;h=c36472790195a470f81b0070c97032fe07272172;hb=acbb02e2775fc3eb0f69c1ee5da9002a4b5dc607;hp=d909b53f31fcd30377adad336f848174dbf7cb82;hpb=b6568b039ee2c8e80350ccfadaad1c561733a2fc;p=catagits%2FCatalyst-Plugin-Email.git diff --git a/Email.pm b/Email.pm index d909b53..c364727 100644 --- a/Email.pm +++ b/Email.pm @@ -116,34 +116,34 @@ 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. - -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. +for HTML pages. If your view supports the 'render' method (Like the TT view +does), you just set the body like this: + $c->email( + header => [ + To => 'me@localhost', + Subject => 'A TT Email', + ], + body => $c->view('TT')->render($c,'mytemplate.tt'), + } + +If your view doesn't support render, you can just forward to it, then reset +the body like this: sub send_email : Local { my ( $self, $c ) = @_; - + { + local $c->stash->{names} = [ qw/andyg sri mst/ ], + local $c->stash->{template}= 'mytemplate.tt'; + $c->forward($c->view('MyView')); $c->email( header => [ To => 'me@localhost', Subject => 'A TT Email', ], - body => $c->subreq( '/render_email' ), - ); - # redirect or display a message - } - - sub render_email : Local { - my ( $self, $c ) = @_; - - $c->stash( - names => [ qw/andyg sri mst/ ], - template => 'email.tt', + body => $c->res->body, ); + $c->res->body(undef); + } } And the template: @@ -174,12 +174,9 @@ L =head1 AUTHOR Sebastian Riedel, C - -=head1 THANKS - -Andy Grundman - Additional documentation - -Carl Franks - Additional documentation +Andy Grundman +Carl Franks +Marcus Ramberg C =head1 COPYRIGHT