如何在SugarCRM中使用电子邮件模板中的条件

Era*_*ira 6 php sugarcrm email-templates

如何在SugarCRM的电子邮件模板中使用if/else条件?我正在尝试使用条件相同的pdf模板和smarty模板,但我没有成功.

没有成功

<?php if ({::past::Opportunities::name::} != {::future::Opportunities::name::}){ ?>
Run Code Online (Sandbox Code Playgroud)

没有成功

{if {::past::Opportunities::name::} neq {::future::Opportunities::name::}}
Run Code Online (Sandbox Code Playgroud)

没有成功

<!-- {if {::past::Opportunities::name::} neq {::future::Opportunities::name::}} -->
Run Code Online (Sandbox Code Playgroud)

有没有成功(?)

??????
Run Code Online (Sandbox Code Playgroud)

谢谢

Paw*_*iel 4

官方 SugarCRM 文档似乎没有提供任何有关在电子邮件模板中使用 if/else 条件的信息。我不相信他们,所以我深入研究了SugarCRM代码。

研究:

发送电子邮件是在EmailMan 类的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);
Run Code Online (Sandbox Code Playgroud)

它使用EmailTemplate 类中的 parse_email_template 方法。写得并不像我想象的那么好。而且它只提供基本的变量替换。让我们仔细看看:

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;
    }
Run Code Online (Sandbox Code Playgroud)

结论:

我还能说更多 - SugarCRM 此时不提供任何条件,也不提供 smarty 或其他模板引擎。您可以尝试修改他们的代码来实现它,但我不建议这样做,因为它是一个小意大利面条;)