25 February 2006
This post may be outdated due to it was written on 2006. The links may be broken. The code may be not working anymore. Leave comments if needed.
It's just another job day.

I'm still working at the "ticket" system. It's almost done expect the user authentication part.

And my previous work gets online now. Pierre(EuropeanServer) just uploaded this script to 1001forums.com. It's a comment system with "captcha"( Authen::Captcha ).

That's my two paid work.

The open-source "ShellWeb" finally switched from CVS to Subversion. But I'm not deeply involved since the code is not so clear to me. Get the lastest source from:

svn co https://svn.sourceforge.net/svnroot/shellweb/trunk shellweb
At last, I want to show your another TT tooltips I asked today.

TT 小提示


我向 [email protected] 邮件组发送了如下这样的问题:
hi, all.

in the front of the code ,I create TT instance like this:

[snip]
use vars qw/$tt/;
my $tt = Template->new({ PRE_PROCESS => 'header', POST_PROCESS => 'footer', [snip] };
my $q = $query->param('q');
[snip]
require "$q.pl";
[snip]

but in one of $q.pl(such as mail.pl, others need the PRE_PROCESS), I don't want the PRE_PROCESS when I call $tt->process
is there a way to change *Config Options* after $tt is created? just like $tt->{PRE_PROCESS} = ''; or something else.
I don't want to create a new TT instance in this $q.pl(mail.pl) since it's ugly.

Thanks for your help.

我的 TT 模版中启用了 PRE_PROCESS 和 POST_PROCESS 参数用于头文件和尾文件。但是程序需要发送一个邮件,而邮件的模版也是一个 tt 文件。但是这个模版不需要头尾文件(因为头文件中包含 HTML 代码,而邮件是纯文本的)。所以就需要暂时性的把 PRE_PROCESS 关闭掉。后来 Sergey Martynoff 在邮件组里回了一个:
For PRE_PROCESS option you can try altering
$tt->service->{PRE_PROCESS} (this should work, although I don't
think it is a good idea).
总算学到了一招。最后在邮件的发送代码中大致是这样的:
my $body; # email Body
               
######################################3
## trick, we don't need the PRE_PROCESS and POST_PROCESS in the mail.tt
$tt->service->{PRE_PROCESS} = [];
$tt->service->{POST_PROCESS} = [];
               
$tt->process('mail.tt', $tt_vars, \$body) || die $tt->error();
               
# call the sub to send mail
require 'sendmail.pl';
$mail_sent = mailer(
   To => $email_to,
   From => $from,
   Subject => $subject,
   Body => $body,
);
用 $tt->service->{PRE_PROCESS} = []; 来改变 config 中的 PRE_PROCESS.
have fun!


blog comments powered by Disqus