Is it possible to use variables in an email template?
3 posts by 2 authors in: Forums > CMS Builder
Last Post: November 6, 2018 (RSS)
Hi All,
I'm passing the value of a checkbox to a section record and also to an email template.
In the email template I'd like to use an if statement to echo a result (text) based on the checkbox value.
And then have that text included in the body of the email that's sent.
As an example:
<?php $var1 = #placeholder# ?>
<?php if ($var1==0):?>some text
<?php elseif ($var1==1):?> some other text
<?php endif ?>
When I insert that into the template, it prints the code, so I guess it's not that straightforward.
Any thoughts?
Thanks,
Jerry Jornbluth
Take advantage of a free 3 month trial subscription, only for CMSB users, at: http://www.thecmsbcookbook.com/trial.php
By daniel - November 6, 2018
Hi Jerry,
The email templates don't support PHP code, but you can use that if/else idea to create a variable to send in as the placeholder instead. It could look something like this:
<?php
$example = !empty($_REQUEST['example']) ? $_REQUEST['example'] : false;
$placholder = '';
if ($example === 0) {
$placeholder = 'some text';
}
elseif ($example === 1) {
$placeholder = 'other text';
}
$emailHeaders = emailTemplate_loadFromDB(array(
'template_id' => 'EXAMPLE-TEMPLATE-ID',
'placeholders' => array(
'placeholder' => $placeholder,
),
));
?>
You'll need to modify it to suit your code, but I hope that gets the basic idea across.
Let me know if you have any questions!
Thanks,
Technical Lead
interactivetools.com
Thanks Daniel,
I kind of figured that, but was hoping for an easy...
Jerry
Take advantage of a free 3 month trial subscription, only for CMSB users, at: http://www.thecmsbcookbook.com/trial.php