Mailing List Archive

C::V::Email::Template email contents includes wrapper ...
I must be doing something really stupid with good old
C::V::Email::Template, but cannot figure out what. Why oh why isn't it
working?

I verified everything using the Chapter 11 example of the new Catalyst
book.

The email arrives alright, but its content has the register.tt2 template
embedded within the html wrapper.tt2 of my app. Some details:

Controller/Register.pm:
-----
$c->stash(
email => {
from => 'no-reply@somewhere.com',
to => "$username <$email>",
subject => 'Registration request',
template => 'mail/register.tt2',
content_type => 'text/plain',
},
);

$c->forward( $c->view('Email::Template') );
-----

View/Email/Template.pm
-----
package MyApp::View::Email::Template;

use strict;
use warnings;

use base 'Catalyst::View::Email::Template';
---

MyApp.pm:
-----
#-- View::Email::Template
__PACKAGE__->config(
'View::Email::Template' => {
stash_key => 'email',
template_prefix => '',
default => {
content_type => 'text/plain',
charset => 'utf-8',
},
sender => {
mailer => 'SMTP',
mailer_args => {
Host => 'mail.somewhere.com',
},
},
}
);

I must be doing something silly, but what?


--
Kiffin Gish <kiffin.gish@planet.nl>
Gouda, The Netherlands


_______________________________________________
Catalyst-dev mailing list
Catalyst-dev@lists.scsys.co.uk
http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst-dev
Re: C::V::Email::Template email contents includes wrapper ... [ In reply to ]
On Mon, Jan 11, 2010 at 7:39 AM, Kiffin Gish <kiffin.gish@planet.nl> wrote:
> I must be doing something really stupid with good old
> C::V::Email::Template, but cannot figure out what. Why oh why isn't it
> working?
>
> I verified everything using the Chapter 11 example of the new Catalyst
> book.
>
> The email arrives alright, but its content has the register.tt2 template
> embedded within the html wrapper.tt2 of my app. Some details:
>
> Controller/Register.pm:
> -----
> $c->stash(
>    email  => {
>        from     => 'no-reply@somewhere.com',
>        to       => "$username <$email>",
>        subject  => 'Registration request',
>        template => 'mail/register.tt2',
>        content_type => 'text/plain',
>    },
> );
>
> $c->forward( $c->view('Email::Template') );
> -----
>
> View/Email/Template.pm
> -----
> package MyApp::View::Email::Template;
>
> use strict;
> use warnings;
>
> use base 'Catalyst::View::Email::Template';
> ---
>
> MyApp.pm:
> -----
> #-- View::Email::Template
> __PACKAGE__->config(
>    'View::Email::Template' => {
>        stash_key => 'email',
>        template_prefix => '',
>        default => {
>            content_type => 'text/plain',
>            charset => 'utf-8',
>        },
>        sender => {
>            mailer => 'SMTP',
>            mailer_args => {
>                Host => 'mail.somewhere.com',
>            },
>       },
>    }
> );
>
> I must be doing something silly, but what?
>
>
> --
> Kiffin Gish <kiffin.gish@planet.nl>
> Gouda, The Netherlands
>


Well, it uses your view template as it is configured. So, it will use
the wrapper if one exists. The way I get around this is to wrap the
wrapper. Something like this:

[%
IF page.wrapper == 'email';
content;
ELSE;
# normal wrapper;
END;
%]

You can then just set page.wrapper = 'email' in all of your *email*
templates and it will work.

-J

_______________________________________________
Catalyst-dev mailing list
Catalyst-dev@lists.scsys.co.uk
http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst-dev
Re: C::V::Email::Template email contents includes wrapper ... [ In reply to ]
Thanks guy, it works like a charm!

I'm a bit surprised that it's not mentioned in any of the documentation,
or is it?

On Mon, 2010-01-11 at 07:47 -0800, J. Shirley wrote:
> On Mon, Jan 11, 2010 at 7:39 AM, Kiffin Gish <kiffin.gish@planet.nl> wrote:
> > I must be doing something really stupid with good old
> > C::V::Email::Template, but cannot figure out what. Why oh why isn't it
> > working?
> >
> > I verified everything using the Chapter 11 example of the new Catalyst
> > book.
> >
> > The email arrives alright, but its content has the register.tt2 template
> > embedded within the html wrapper.tt2 of my app. Some details:
> >
> > Controller/Register.pm:
> > -----
> > $c->stash(
> > email => {
> > from => 'no-reply@somewhere.com',
> > to => "$username <$email>",
> > subject => 'Registration request',
> > template => 'mail/register.tt2',
> > content_type => 'text/plain',
> > },
> > );
> >
> > $c->forward( $c->view('Email::Template') );
> > -----
> >
> > View/Email/Template.pm
> > -----
> > package MyApp::View::Email::Template;
> >
> > use strict;
> > use warnings;
> >
> > use base 'Catalyst::View::Email::Template';
> > ---
> >
> > MyApp.pm:
> > -----
> > #-- View::Email::Template
> > __PACKAGE__->config(
> > 'View::Email::Template' => {
> > stash_key => 'email',
> > template_prefix => '',
> > default => {
> > content_type => 'text/plain',
> > charset => 'utf-8',
> > },
> > sender => {
> > mailer => 'SMTP',
> > mailer_args => {
> > Host => 'mail.somewhere.com',
> > },
> > },
> > }
> > );
> >
> > I must be doing something silly, but what?
> >
> >
> > --
> > Kiffin Gish <kiffin.gish@planet.nl>
> > Gouda, The Netherlands
> >
>
>
> Well, it uses your view template as it is configured. So, it will use
> the wrapper if one exists. The way I get around this is to wrap the
> wrapper. Something like this:
>
> [.%
> IF page.wrapper == 'email';
> content;
> ELSE;
> # normal wrapper;
> END;
> %]
>
> You can then just set page.wrapper = 'email' in all of your *email*
> templates and it will work.
>
> -J
>
> _______________________________________________
> Catalyst-dev mailing list
> Catalyst-dev@lists.scsys.co.uk
> http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst-dev


--
Kiffin Gish <kiffin.gish@planet.nl>
Gouda, The Netherlands



_______________________________________________
Catalyst-dev mailing list
Catalyst-dev@lists.scsys.co.uk
http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst-dev
Re: C::V::Email::Template email contents includes wrapper ... [ In reply to ]
On Mon, Jan 11, 2010 at 8:11 AM, Kiffin Gish <kiffin.gish@planet.nl> wrote:
> Thanks guy, it works like a charm!
>
> I'm a bit surprised that it's not mentioned in any of the documentation,
> or is it?
>


No, don't believe it is. But dhoss is working on the next version of
C::V::Email so I'll see about getting it in there.

-J

_______________________________________________
Catalyst-dev mailing list
Catalyst-dev@lists.scsys.co.uk
http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst-dev
Re: C::V::Email::Template email contents includes wrapper ... [ In reply to ]
That'd be great, thanks. For the more experienced folks this may seem
obvious, but for beginners I can imagine it needs to be explained.

Perhaps another option might be to create a completely new view, e.g.
TTMail, one which is not configured with a WRAPPER, and then use that
explicitly as the view rather than the default View => 'TT'.

The use of IF page.wrapper == 'email' seems like a hack, but if it's the
standard way then okay.

On Mon, 2010-01-11 at 08:18 -0800, J. Shirley wrote:
> On Mon, Jan 11, 2010 at 8:11 AM, Kiffin Gish <kiffin.gish@planet.nl> wrote:
> > Thanks guy, it works like a charm!
> >
> > I'm a bit surprised that it's not mentioned in any of the documentation,
> > or is it?
> >
>
>
> No, don't believe it is. But dhoss is working on the next version of
> C::V::Email so I'll see about getting it in there.
>
> -J
>
> _______________________________________________
> Catalyst-dev mailing list
> Catalyst-dev@lists.scsys.co.uk
> http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst-dev


--
Kiffin Gish <Kiffin.Gish@planet.nl>
Gouda, The Netherlands



_______________________________________________
Catalyst-dev mailing list
Catalyst-dev@lists.scsys.co.uk
http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst-dev
Re: C::V::Email::Template email contents includes wrapper ... [ In reply to ]
On Jan 11, 2010, at 1:02 PM, Kiffin Gish wrote:

> Perhaps another option might be to create a completely new view, e.g.
> TTMail, one which is not configured with a WRAPPER, and then use that
> explicitly as the view rather than the default View => 'TT'.

For what it's worth, this is exactly what I do. I create a separate View::TT class called 'Text' that reassigns the template root, and doesn't define a wrapper. Very little overhead, and far cleaner (imho). A few different parts of the code use the 'Text' view, it certainly comes in handy for separation.

- Nick
_______________________________________________
Catalyst-dev mailing list
Catalyst-dev@lists.scsys.co.uk
http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst-dev
Re: C::V::Email::Template email contents includes wrapper ... [ In reply to ]
On Mon, Jan 11, 2010 at 11:02 AM, Kiffin Gish <kiffin.gish@planet.nl> wrote:
> That'd be great, thanks. For the more experienced folks this may seem
> obvious, but for beginners I can imagine it needs to be explained.
>
> Perhaps another option might be to create a completely new view, e.g.
> TTMail, one which is not configured with a WRAPPER, and then use that
> explicitly as the view rather than the default View => 'TT'.
>
> The use of IF page.wrapper == 'email' seems like a hack, but if it's the
> standard way then okay.


I don't view it as a hack, because I've found this to be very useful
in the main application for generating the email just via another view
call.

I also use this wrapper, and then other tweaks, for generating the
"Print Receipt" mechanism.

This is also in contrast with a "partial" wrapper, which doesn't
provide the email-friendly header/footer stuff.

If you don't need that, a second view is probably the easier way to do it.

-J

_______________________________________________
Catalyst-dev mailing list
Catalyst-dev@lists.scsys.co.uk
http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst-dev