FW: [rt-users] choosing template on the fly

Ruslan U. Zakirov cubic at acronis.ru
Tue May 11 12:14:11 EDT 2004


I like your idea and solution, but I refactored it a little into _Local 
overlay file which doesn't touch Prepare sub. It use TemplateObj sub 
cause it simple and right places to do such override.

I've done only use_ok test. Could you test it? Then I or you can fill it 
in wiki page.

Comment about strange code below.

				Best regards. Ruslan.

Dimitry Faynerman wrote:
[snip]
> 
> Here's the code:
> 
> sub Prepare {
>     my $self = shift;
> 
>     # This actually populates the MIME::Entity fields in the Template Object
> 
>     unless ( $self->TemplateObj ) {
>         $RT::Logger->warning("No template object handed to $self\n");
>     }
> 
>     # my changes start here ===============================================
>     # Use japanese template (if exists) if user's language is japanese
> 
>     my $UserObj = RT::User->new( $RT::SystemUser );
>     $UserObj->Load($self->TicketObj->Requestors->UserMembersObj->First->Id);
> 
>     if (($self->TemplateObj) &&
>         ((!$UserObj->Lang) || ($UserObj->Lang ne 'en'))) {
This 'if condition' will be true if $UserObj->Lang is not defined or 
empty string. Refactored code has slightly different condtion.


>        my $rememberEnglishId = $self->TemplateObj->Id;
>        $self->TemplateObj->Load(
>             $self->TemplateObj->Name . " (" . $UserObj->Lang . ")");
>        if (! $self->TemplateObj->Id) {
>           $self->TemplateObj->Load($rememberEnglishId);
>        }
>     }
>     # my changes end here ===============================================
> 
> 
[snip]
> -Dimitry
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: SendEmail_Local.pm
URL: <http://lists.bestpractical.com/pipermail/rt-users/attachments/20040511/d9b92595/attachment.ksh>


More information about the rt-users mailing list