How I can use if/else conditions inside the email template in SugarCRM? I am trying use conditions equal pdf template and smarty template but I have no success.
No success
<?php if ({::past::Opportunities::name::} != {::future::Opportunities::name::}){ ?>
No success
{if {::past::Opportunities::name::} neq {::future::Opportunities::name::}}
no success
<!-- {if {::past::Opportunities::name::} neq {::future::Opportunities::name::}} -->
Any success (?)
??????
Thanks
It seems, that official SugarCRM docs don't provide any information about using if/else conditions in email templates. I didn't believed them, so i dug into SugarCRM code.
Research:
Sending e-mail is done in EmailMan class in method sendEmail:
$template_data = $this->current_emailtemplate
->parse_email_template(
array(
'subject' => $this->current_emailtemplate->subject,
'body_html' => $this->current_emailtemplate->body_html,
'body' => $this->current_emailtemplate->body,
)
, $focus_name, $module
, $macro_nv);
It uses parse_email_template method from class EmailTemplate. It's not so well-written, as i was thinking. And it's only providing basic variable replacing. Let's look at it a little closer:
function parse_email_template($template_text_array, $focus_name, $focus, &$macro_nv)
{
[...] //variable initiation
//preparing prefixes to search for variables (all variables are in "$some_name" format
$pattern_prefix = '$' . strtolower($beanList[$focus_name]) . '_';
$pattern_prefix_length = strlen($pattern_prefix);
$pattern = '/\\' . $pattern_prefix . '[A-Za-z_0-9]*/';
foreach ($template_text_array as $key => $template_text) {
[...] //searching for variables matching $pattern and replacing them with proper values
$return_array[$key] = $template_text;
}
return $return_array;
}
Conclusion:
What i can say more - SugarCRM at this point doesn't provide any conditions nor smarty or other template engine. You can try to modify their code to implement it, but i wouldn't recommend that as it is a litlle spaghetti ;)
handlebarsjs may help?
http://handlebarsjs.com/builtin_helpers.html
{{#if yourcondition}} action {{else}} action{{/if}}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With