Categories > TinyButStrong general >

eMail subject with vars

The forum is closed. Please use Stack Overflow for submitting new questions. Use tags: tinybutstrong , opentbs
By: chris
Date: 2016-06-28
Time: 10:55

eMail subject with vars


I got a system running with TBS. It's perfekt for my use and easy to setup. Great stuff! Thanks!

But now I've got an email template which is running fine so far. Next step would be to customize the subject additional vars like this:
[onload;tplvars;subject=ZIP Event - Trainer-Bewerbung [Event.eid] [Event.send_by];comm=_]
Any Idea, how I can include the var  [Event.eid] [Event.send_by] into my subject line without doing it inside my php script? The Idea is, that you totally configure the email without touching the php.

Thanks in advance,
By: Skrol29
Date: 2016-06-29
Time: 01:53

Re: eMail subject with vars


There is a trick for doing this.

[myblock;tplvars;subject=ZIP Event - Trainer-Bewerbung [Event.eid] [Event.send_by];enlarge=_]
$TBS->MergeField('Event'; ...);
$TBS->MergeBlock('myblock', 'cond'); // Merges the block as if it [onload] or [onshow]

But in fact as soon as block « Event » is merged, then the parameter « subject=ZIP Event - Trainer-Bewerbung [Event.eid] [Event.send_by] » becomes unclean because variables may be replaced with special characters that may corrupt the syntax. For examples : ";" or "]".
The clean solution is :

[onload;tplvars;subject=ZIP Event - Trainer-Bewerbung [Event.eid] [Event.send_by];enlarge=_]
// retrieve subject and merge fields inside
$save_template = $TBS->Source; // save the current template
$TBS->Source = $TBS->TplVars['subject']; // replace template with the string to merge
$TBS->MergeField('Event'; $data); // merge the string
$subject = $TBS->Source; // save the result
$TBS->Source = $save_template; // restore first template