SugarCRM white papers do not seem to provide any information about using if / else clauses in email templates. I did not believe them, so I got into SugarCRM code.
Study:
Email is sent in the EmailMan class in the sendEmail method:
$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 the parse_email_template method of the EmailTemplate class . It was not as well written as I thought. And this only provides a replacement for the main variable. Let's look at this 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; }
Output:
What can I say more - SugarCRM currently does not provide any conditions, not smarty or another template engine. You can try changing your code to implement it, but I would not recommend this, since it is litlle spaghetti ;)
source share