Scenario
You're trying to send an email (via Catalyst::Plugin::Email, MIME::Lite, Email::Sender::Simple, your choice) and you would like to be able to stuff your canned email messages into their respective Template::Toolkit templates. One way to do this is use Catalyst::View::Email::Template, which is pretty cool, but forces you to use Catalyst::View::Email, which some people aren't too keen on. So, you can do something like this:
sub email_stuff : Local {
my ($self, $c, $review_id) = @_;
$c->stash(
review_url => $c->uri_for("/thingy/${review_id}"),
status_msg => "Thank you for your feedback!",
template => 'view_all.tt2',
);
$c->email(
header => [
From => $c->config->{'from'},
To => $c->config->{'to'},
Subject => "Emaily stuff!",
],
body => $c->view('TT')->render($c, 'review.tt2'),
);
return;
}
The line $c->view('TT')->render($c, 'review.tt2') allows you to have your view render your template for you using all the things you put into $c->stash. Pretty cool eh?




dont forget to trap errors.
my $body = $c->view('TT')->render( $c, 'alerts/add_new.tt' );
if ( ref($body) eq 'Template::Exception' ) { die $body->as_string; }
Good catch! Thanks for that.