Gossamer Forum
Home : Products : Gossamer Links : Development, Plugins and Globals :

Way to pass in a template set into send_email() ?

Quote Reply
Way to pass in a template set into send_email() ?
Hi,

I'm trying to work out the best way to send an email from a script in SSH. I wanna be able to pass a template set (based on the language preferance of the user its being sent to). From a web-based script, you would just need to pass in t=xxx ... but I'm having to do a bit of a dirty hack to Links.pm send_email() to try and get this to work:

Code:
$parsed = user_page($template, $vars, { compress => 0 });

..to:

Code:
if ($_[2]->{template}) {
$parsed = user_page($template, $vars, { compress => 0, template => $_[2]->{template} });
} else {
$parsed = user_page($template, $vars, { compress => 0 });
}

Then user_page():

Code:
$vars = $vars->get_hash if UNIVERSAL::isa($vars, 'GT::CGI');
$IN->param('t' => $opts->{template} ); # added

Then in my script:

Code:
Links::send_email('validate.eml', $user, { template => 'fr' } ) or die "Unable to send message: $GT::Mail::error";

Not ideal :) Is there a better way to pass this along to send_email() ? My solution works, but if there is a built-in way, I would prefer to use that (so I don't break the updates)

TIA

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Andy] Way to pass in a template set into send_email() ? In reply to
Mmmm actually, that doesn't work :( It always uses the last value (as $IN->param overwrites the first time I guess). I've also tried another method, but the problem is that it seems language.txt takes the values from "t" being passed in. Due to the way I'm trying to get my templates to work, I'm not sure how to do it.

To make translations easier I'm using different templates set for language.txt file. Then the emails look like:

Code:
To: <%if Name%><%Name%> <<%Email%>><%else%><%Email%><%endif%>
From: Waaaant! <<%config.db_admin_email%>>
Subject: <%Links::language("EMAIL_VAL_CODE_TITLE")%>
Content-Type: text/html

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title><%Links::language("EMAIL_VAL_CODE_TITLE")%></title>
<%include common_header.eml%>
</head>
<body>

(notice it use Links::language() ). What appears to be the problem, is that although my "hack" has told it to use the french template set - this gets ignored by Links::language()... and AFAIK there is no way to pass the template set along to Links::language, without it being sent in as a "t" param?

Bit of a sod :( Anyone got any suggestions? Otherwise I guess it means keeping multiple versions of the templates _en and _fr ... but this much more admin work - especially when more languages are added Crazy)

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Andy] Way to pass in a template set into send_email() ? In reply to
Hi,

Ok, well I found a better solution :)

lang_custom
Code:
sub {
my $LANGUAGE = GT::Config->load("$CFG->{admin_root_path}/templates/$_[0]/language.txt", { local => 1 });
return { LANG => $LANGUAGE }
}

Then call at the top of the emails with:

Code:
<%lang_custom($what_lang)%>

Then you have access to all the english stuff in <%LANG.FOO_BAR%> ... and call the send_email() like:

Code:
send_email('template.eml', { params => "foo", what_lang => "fr" } );

Seems to do the trick Cool (and means that the system is upgradable still, without loosing anything)

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!

Last edited by:

Andy: Feb 7, 2013, 2:33 AM